Menu
Topics Index
...
`

Method Overriding


If you need explanation Read this topic

If you need Answer Take test on this topic

Method Overriding
What will be the output of the following program?
class Person {
    public void talk() {
        System.out.print("First Program");
    }
}
class Student extends Person {
    public void talk() {
        System.out.print("Second Program");
    }
}
public class TestProgram {
    public static void main(String args[]) {
        Person p = new Student();
        p.talk();
    }
}

A. First Program
B. Second Program
C. First ProgramSecond Program
D. Second ProgramFirst Program
E. Compilation Error or Runtime Error
Topic: Method Overriding In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Answer is B,
We are creating student object so students talk() method will be executed.

Posted by Amar Kumar Biradar    2013-11-20 04:02:00


Ans is B,bcoz if we create object to the subclass with super class reference variable,we can access only super class variables and subclass methods with that object.

Posted by Raviteja Daggupati    2013-11-20 06:21:38


Congratulations Amar Kumar Biradar. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2013-11-21 03:34:12


© meritcampus 2019

All Rights Reserved.

Open In App