20) Consider the following code snippet: public class Vehicle { private String m
ID: 3657015 • Letter: 2
Question
20) Consider the following code snippet: public class Vehicle { private String manufacturer; . . . public void setVehicleClass(double numberAxles) { . . . } } If a Motorcycle class is created as a subclass of the Vehicle class, which of the following statements is correct? a) A Motorcycle object inherits and can directly use both the instance variable manufacturer and the method setVehicleClass. b) A Motorcycle object inherits and can directly use the instance variable manufacturer but not the method setVehicleClass. c) A Motorcycle object inherits but cannot directly use either the instance variable manufacturer or the method setVehicleClass. d) A Motorcycle object inherits and can directly use the method setVehicleClass but cannot directly use the instance variable manufacturer.Explanation / Answer
Option (D) is correct. since the instance variable(Private String manufacturer;) is declared as private the subclasses wont have access to it. But the method is declared as public so the subclasses can access the method directly
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.