Method Overriding
About
Why Overriding is Important ?
What Happens When We Override ?
Rules for Method Overriding
1. The Method Must Be Inherited
2. Method Signature Must Be Exactly the Same
3. Return Type Must Be the Same or a Subtype (Covariant Return)
4. Access Modifier Cannot Be More Restrictive
Superclass Modifier
Allowed in Subclass
Not Allowed in Subclass
5. Cannot Override Static Methods
6. Cannot Override Final Methods
7. Exception Rules (Checked Exceptions)
8. Use of @Override Annotation (Optional but Recommended)
@Override Annotation (Optional but Recommended)9. Abstract Methods Must Be Overridden
Last updated