Menu
Topics Index
...
`

Rules for abstract methods and abstract classes2832


If you need explanation Read this topic

If you need Answer Take test on this topic

Rules for abstract methods and abstract classes2832
What will be the output of the following program?
public class Test {
    public static void main(String[] args) {
        new Z().method1();
        new Z().method2();
    }
}
abstract class X {
    abstract void method1();
    abstract void method2();
}
abstract class Y extends X {
    void method1() {
        System.out.println("Method1 implemented here.");
    }
}
class Z extends Y {
    void method2() {
        System.out.println("Method2 implemented here.");
    }
}

A. Method2 implemented here.
B. Method1 implemented here.
C. Method1 implemented here.
Method2 implemented here.
D. Compilation Error or Runtime Error
Topic: Rules For Abstract Methods and Abstract Classes

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.

B

Posted by Uha Mateti    2014-08-20 12:41:43


ans C,  first main started and class Z with method1 is called then Z is extended by Y so method1 executed, and after that method2 will execute .

Posted by Damu Surya    2014-08-20 12:59:55


ans D  non-static variable this cannot be referenced from a static context

Posted by Ramya Reddy Addulla    2014-08-20 13:07:08


D

Posted by Prabhakar Reddy    2014-08-20 13:23:49


d.compilation error..since non static variabl ccannot b refrncd wid static contxt

Posted by Asma Mujtaba Khan    2014-08-20 13:29:39


C

Posted by Shashanka Mogaliraju    2014-08-20 16:16:19


Congratulations Damodar U Ukkala. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-08-21 05:15:06


© meritcampus 2019

All Rights Reserved.

Open In App