Overriding

Overriding methods:
It allows a subclass to re-define a method it inherits from it's superclass
Overriding methods:
1. It appears in subclasses
2. They have the same name as a superclass method. 
3. They have the same parameter list as a superclass method. 
4. They have the same return type as as a superclass method. 
5. They have the access modifier for the overriding method may not be more restrictive than the access modifier of the superclass method.
  • If the superclass method is public, the overriding method must be public. 
  • If the superclass method is protected, the overriding method may be protected or public.
  • If the superclass method is default, the overriding method may be default, protected, or public.
  • If the superclass methods is private, it is not inherited and overriding is not an issue.
 





Leave a Reply.