Menu
Topics Index
...
`

Final Classes


If you need explanation Read this topic

If you need Answer Take test on this topic

Final Classes
What will be the output of the following program?
final class Base {
    public void testMethod() {
        System.out.println("Final class");
    }
}
final class Inter {
    public void testMethod() {
        System.out.println("Inter Class");
    }
}
public class Sub extends Base {
    public void testMethod() {
        System.out.println("Sub class extends the Base class");
    }
    public static void main(String arg[]) {
        Sub sub = new Sub();
        Base obj = new Base();
        obj.testMethod();
        Inter inte = new Inter();
        inte.testMethod();
        sub.testMethod();
    }
}

A. Sub class extends the Final Base class
Inter Class
Sub class extends the Final Base class
B. Final class
Inter Class
Sub class extends the Final Base class
C. Final class
Inter Class
Final class
D. Some other output
E. Compilation Error or Runtime Error
Topic: final Keyword 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.

Ans is E. Compilation error occurs. The Base class is defined as final. So it can be inherited by any class. Here Sub class is extending the Base class which is not possible.

Posted by Nikhil Sulibhavi    2014-05-09 13:00:05


ans is e...final class cant be ingerited...

Posted by Uday Kumar    2014-05-09 13:01:55


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

Posted by Merit Campus    2014-05-12 04:22:12


© meritcampus 2019

All Rights Reserved.

Open In App