Can we override a method in the same class?

  • No, it is not allowed
  • Yes, but it has no practical purpose
  • Yes, it is allowed
  • Yes, with different method names
In Java, method overriding occurs when a subclass provides a specific implementation for a method that is already defined in its superclass. Therefore, it is not possible to override a method in the same class because there is no superclass-subclass relationship. However, you can overload methods within the same class by defining methods with the same name but different parameter lists.
Add your answer
Loading...

Leave a comment

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