Question: What would be the result of compiling and running the following program? Select the one correct answer. (a) The code will fail to compile. (b)
What would be the result of compiling and running the following program?

Select the one correct answer.
(a) The code will fail to compile.
(b) The code will compile, and print |Toyota|Volvo|12345|54321| at runtime.
(c) The code will compile, and print |Volvo|Toyota|12345|54321| at runtime.
(d) The code will compile, and print |Toyota|Toyota|12345|12345| at runtime.
(e) The code will compile, and print |Volvo|Volvo|12345|54321| at runtime.
(f) The code will compile, and print |Toyota|Toyota|12345|12345| at runtime.
(g) The code will compile, and print |Volvo|Toyota|54321|54321| at runtime.
class Vehicle { static public String getModelName () { return "Volvo"; } public long getRegNo () { return 12345; } } class Car extends Vehicle { static public String getModel Name () { return "Toyota"; } public long getRegNo () { return 54321; } } public class TakeARide ( public static void main (String [] args) { Car c= new Car (); Vehicle v = C; System.out.println ("|" + v.getModelName () + "" + c.getModelName() + "I" + v.getRegNo () + "" + c.getRegNo () + "|"); }
Step by Step Solution
3.57 Rating (164 Votes )
There are 3 Steps involved in it
g In the class Car the static method getModelName hides the static method of the same nam... View full answer
Get step-by-step solutions from verified subject matter experts
