What is the output of the following Java program no. 12?
- 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();
- }
- }
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.
Recent Posts