Java | Inheritance | Question 2

filter_none

edit
close

play_arrow

link
brightness_4
code

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();
    }
}

chevron_right


(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



My Personal Notes arrow_drop_up


Article Tags :

1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.