1. The code compiles and displays "mpg: 50" if the command-line argument is "Hiway". If the command-line argument is not "Hiway", the code displays "mpg: 25". 2. The code compiles and displays "mpg: 50" if the command-line argument is "Hiway". If the command-line argument is not "Hiway", the code throws an ArrayIndexOutOfBoundsException. 3. The code does not compile because the automatic variable named index has not been initialized. 4. The code does not compile because milesPerGallon has not been initialized. 5. The code does not compile because the no-args constructor is not written correctly
Correct Answer : 3
why ? As i think index is initialized in the constructor call at line 8. Then why option c is correct. Explain.
The variable index declared in Class car is not static. So main method cannot access non static variables directly without having an instance of the class. Secondly, index variable declared in main method is not initialized but trying to use it and hence the compilation error.