Menu
Topics Index
...
`

Output is2274


If you need explanation Read this topic

Output is2274
What will be the output of the following program?
public class IAm {
    public static void main(String arg[]) {
        School ref = null;
        ref = new Office();
        ref.display();
    }
}
class School {
    void display() {
        System.out.println("10th class");
    }
}
class College extends School {
    void display() {
        new School().display();
        System.out.println("B.Tech");
    }
}
class Office extends School {
    void display() {
        new College().display();
        System.out.println("S/W company");
    }
}

A. 10th class
B. B.Tech
10th class
S/W company
C. 10th class
B.Tech
S/W company
D. S/W company
B.Tech
10th class
E. Compilation Error or Runtime Error
Topic: Dynamic Method Dispatch - Calling Overridden Methods In Java

If you need explanation Read this topic

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

Answer is c.ref.display will call display in office class which inturn calls display in college and inturn display in school class

Posted by Shashanka Mogaliraju    2014-09-02 08:33:25


c

Posted by Zeg Abder    2014-09-02 08:41:46


From main office gets called ,then from office it turn towards college and from college towards school.. Super class execute first then college and then office. So,ans is C

Posted by Akshay Bansod    2014-09-02 10:51:09


ans is C ,,, first  school then college then office goes to heap section in memory

Posted by Raju VarshnEy    2014-09-02 11:16:48


Congratulations Shashanka Mogaliraju. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-09-03 04:17:43


© meritcampus 2019

All Rights Reserved.

Open In App