Open In App

Java | Inheritance | Question 2

Like Article
Like
Save
Share
Report




class Base {
    final public void show() {
       System.out.println("Base::show() called");
    }
}
   
class Derived extends Base {
    public void show() {
       System.out.println("Derived::show() called");
    }
}
   
class Main {
    public static void main(String[] args) {
        Base b = new Derived();;
        b.show();
    }
}


(A) Base::show() called
(B) Derived::show() called
(C) Compiler Error
(D) Runtime Error


Answer: (C)

Explanation: Final methods cannot be overridden. See the compiler error here.

Quiz of this Question


Last Updated : 28 Jun, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads