According to method overriding, an overriding method must follow the following rules:
- It must have the same argument list.
- It must have the same return type, new to Java 5. The return type can be a subclass – this is known as covariant return.
- It must not have a more restrictive access modifier.
- It may have a less restrictive access modifier.
- It must not throw new or broader checked exceptions.
- It may throw fewer or narrower checked exceptions, or any unchecked exception.
Responses to “What are the rules for method overriding?”