+ 2

Using the same variable in different classes (known as global)

I created a car race game using Java, it is based on threads so each car is racing in parallel with the others, while the sequence of reaching the finish line is random. Now I want to develop the code to control the winner, the main class gets an input from the user to pick his car out of four, let's define 'pick'. I want 'pick' to control other variable 'acc': switch (pick) { case 1: acc=... case 2: acc=.. case 3: acc=.. case 4: acc=.. } https://code.sololearn.com/cZhc60SBIiEC/?ref=app

19th Aug 2017, 4:39 PM
Ziv
Ziv - avatar
1 Odpowiedź
+ 2
Each car is an object of a sub-class which inherent from Car super class. ****Finally The question is:***** how can I use 'acc' in the cars' sub-classes?
19th Aug 2017, 4:43 PM
Ziv
Ziv - avatar