Java | Inheritance | Question 5
Output of following Java program?
class Base { public void Print() { System.out.println( "Base" ); } } class Derived extends Base { public void Print() { System.out.println( "Derived" ); } } class Main{ public static void DoPrint( Base o ) { o.Print(); } public static void main(String[] args) { Base x = new Base(); Base y = new Derived(); Derived z = new Derived(); DoPrint(x); DoPrint(y); DoPrint(z); } } |
(A)
Base Derived Derived
(B)
Base Base Derived
(C)
Base Derived Base
(D) Compiler Error
Answer: (A)
Explanation: See question 1 of https://www.geeksforgeeks.org/output-of-java-program-set-2/
Quiz of this Question
Please Login to comment...