Menu
Question Index
...

What will be the output of the following program?

class X
{
    private int a;
    int b;
    public void m1()
    {
        System.out.println("This is method m1 of class X");
    }
}
class Y extends X
{
    int c;
    public void m1()
    {
        System.out.println("This is method m1 of class Y");
    }
    public void m2()
    {
        super.m1();
        System.out.println("This is method m2 of class Y");
    }
}
class Test
{
    public static void main(String args[])
    {
        X x = new X();
        Y y = new Y();
        y.m2();
        x.m1();
        y.m1();
        x = y;
        x.m1();
    }
}


This is method m1 of class X
This is method m2 of class Y
This is method m1 of class X
This is method m1 of class Y
This is method m1 of class Y
This is method m1 of class Y
This is method m2 of class Y
This is method m1 of class X
This is method m1 of class Y
This is method m1 of class X
This is method m1 of class Y
This is method m2 of class Y
This is method m1 of class Y
This is method m1 of class X
This is method m1 of class X
This is method m1 of class X
This is method m2 of class Y
This is method m2 of class Y
This is method m1 of class X
This is method m1 of class Y
Compilation Error or Runtime Error

Doubts

Problems

Topic: Unknown

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App