Multiple choice technology programming languages

Click the Exhibit button. 1. public class Car { 2. private int wheelCount; 3. private String vin; 4. public Car(String vin) { 5. this.vin = vin; 6. this.wheelCount = 4; 7. } 8. public String drive() { 9. return “zoom-zoom”; 10. } 11. public String getInfo() { 12. return “VIN: “+ vin + “wheels: “+ wheelCount; 13. } 14. } And: 1. public class MeGo extends Car { 2. public MeGo(String vin) { 3. this.wheelCount = 3; 4. } 5. } What two must the programmer do to correct the compilation errors? (Choose two.)

  1. insert a call to this() in the Car constructor

  2. insert a call to this() in the MeGo constructor

  3. insert a call to super() in the MeGo constructor

  4. insert a call to super(vin) in the MeGo constructor

  5. change the wheelCount variable in Car to protected

  6. change line 3 in the MeGo class to super.wheelCount = 3;

Reveal answer Fill a bubble to check yourself
D,E Correct answer
Explanation

MeGo's constructor tries to access this.wheelCount, but wheelCount is private in Car. Even in a subclass, private members are not accessible - they must be protected or public. Option E correctly identifies this. Also, MeGo's constructor must call super(vin) to invoke Car's constructor since Car has no no-arg constructor - Java doesn't automatically insert super() when the parent lacks a no-arg constructor. Option D correctly identifies this.

AI explanation

Car has no no-argument constructor — its only constructor requires a vin — so MeGo's constructor, which doesn't explicitly call a superclass constructor, needs super(vin) to satisfy that requirement. Separately, wheelCount is private in Car, so MeGo cannot access it directly as this.wheelCount; making it protected allows subclasses to reference it. Both fixes are needed together for the code to compile.