Topic:   What is the output of the following Java program?
Apr 09, 2021 11:56 1 Replies 128 Views VAMSI

What is the output of the following Java program?

  1. class Base
  2. {
  3. protected final void getInfo()
  4. {
  5. System.out.println("method of Base class");
  6. }
  7. }
  8.  
  9. public class Derived extends Base
  10. {
  11. protected final void getInfo()
  12. {
  13. System.out.println("method of Derived class");
  14. }
  15. public static void main(String[] args)
  16. {
  17. Base obj = new Base();
  18. obj.getInfo();
  19. }
  20. }
Prev Next
Topic Replies (1)
  1. 1
    idnkx user

    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.

Leave a Reply
Guest User

Not sure what course is right for you?

Choose the right course for you.
Get the help of our experts and find a course that best suits your needs.


Let`s Connect