Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

48) Consider the following code snippet: Vehicle aVehicle = new Auto(); aVehicle

ID: 3657022 • Letter: 4

Question

48) Consider the following code snippet: Vehicle aVehicle = new Auto(); aVehicle.moveForward(200); If the Auto class inherits from the Vehicle class, and both classes have an implementation of the moveForward method with the same set of parameters and the same return type, which statement is correct? a) The moveForward method of the Auto class will be executed. b) The moveForward method of the Vehicle class will be executed. c) You must specify in the code which class's moveForward method is to be used. d) It is not possible to determine which class's method is called.

Explanation / Answer

a) The moveForward method of the Auto class will be executed. Example: class Vehicle { int moveForward(int value){ return value*value; } } public class Auto extends Vehicle{ int moveForward(int value){ return value+value; } public static void main(String[] args) { Vehicle aVehicle = new Auto(); System.out.println(aVehicle.moveForward(200)); } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote