Topic: What is the output of the following Java program?
What is the output of the following Java program?
- class Base
- {
- protected final void getInfo()
- {
- System.out.println("method of Base class");
- }
- }
- public class Derived extends Base
- {
- protected final void getInfo()
- {
- System.out.println("method of Derived class");
- }
- public static void main(String[] args)
- {
- Base obj = new Base();
- obj.getInfo();
- }
- }
Author: VAMSI
JOSHUA
Output
Derived.java:11: error: getInfo() in Derived cannot override getInfo() in Base
protected final void getInfo()
^
overridden method is final
1 error
Explanation
The getDetails() method is final; therefore it can not be overridden in the subclass.