What is the output of this code?.
public class Car { public void startup() { System.out.print("computer-"); } /* w w w. j ava2 s. c om*/ public static void main(String[] args) { Car computer = new MyCar(); MyCar laptop = new MyCar(); computer.startup(); laptop.startup(); } } class MyCar extends Car { public void startup() { System.out.print("laptop-"); } }
C.
Both objects are instances of the class MyCar
.
The startup()
method in the MyCar
class gets called both times thanks to polymorphism.