What will happen if the overriding method is static in the superclass?

  • It will lead to a compile-time error.
  • The static method in the subclass will hide the static method in the superclass.
  • The static method in the subclass will override the static method in the superclass.
  • The static method in the superclass will hide the static method in the subclass.
When a method is declared as static in both the superclass and the subclass, it does not represent method overriding but method hiding. In such cases, the static method in the subclass will hide (not override) the static method in the superclass. The choice of which method to invoke depends on the reference type. If you call the method on the superclass reference, the superclass method is invoked; if you call it on the subclass reference, the subclass method is invoked.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *