You have the following class definitions: public abstract class Vehicles { } public class Bus { } public class MyClass { public Vehicles go() { return new Bus(); } } What change would have to be made to allow this code to compile?
-
- Change public abstract class Vehicles { } to public class Vehicles { }
-
- Change public class Bus { } to public class Bus extends Vehicles { }
-
- Change public class MyClass { to private class My Class {
-
- Change public abstract class Vehicles { } to protected abstract class Vehicles { }
B
Correct answer
Explanation
The go() method returns Vehicles but tries to return a Bus instance. This is only valid if Bus is a subclass of Vehicles. Changing Bus to extend Vehicles establishes this inheritance relationship, allowing the return.