Recall & Review
beginner
What is method overriding in Java?
Method overriding occurs when a subclass provides a specific implementation for a method that is already defined in its superclass with the same name, return type, and parameters.Click to reveal answer
intermediate
Can the access modifier of an overriding method be more restrictive than the overridden method?
No, the overriding method cannot have a more restrictive access modifier. It can have the same or a less restrictive modifier to maintain accessibility.
Click to reveal answer
intermediate
Is it allowed to override a static method in Java?
No, static methods cannot be overridden. They can be hidden by another static method in the subclass, but this is not true overriding.
Click to reveal answer
advanced
What happens if the overriding method throws a checked exception not declared in the overridden method?
The overriding method cannot throw new or broader checked exceptions than the overridden method. It can throw fewer or narrower exceptions or none at all.
Click to reveal answer
intermediate
Can the return type of the overriding method differ from the overridden method?
Yes, since Java 5, the overriding method can have a covariant return type, meaning it can return a subtype of the original method's return type.
Click to reveal answer
Which of the following is true about method overriding in Java?
✗ Incorrect
Method overriding requires the same method name and parameters. The return type can be the same or a subtype (covariant). Access modifier cannot be more restrictive. Static methods cannot be overridden.
If a superclass method throws IOException, what exceptions can the overriding subclass method throw?
✗ Incorrect
The overriding method can throw the same checked exception or its subclasses, or no exception. It cannot throw new or broader checked exceptions.
What happens if you try to override a private method in Java?
✗ Incorrect
Private methods are not visible to subclasses, so defining a method with the same signature creates a new unrelated method, not an override.
Which access modifier is allowed for an overriding method if the original method is declared as protected?
✗ Incorrect
The overriding method can have the same or less restrictive access modifier. Since protected is less restrictive than private and default, it can be protected or public.
Can a final method be overridden in Java?
✗ Incorrect
Final methods cannot be overridden to prevent modification of their behavior.
Explain the key rules you must follow when overriding a method in Java.
Think about method signature, access, exceptions, and special method types.
You got /5 concepts.
Describe what happens if you try to override a private or static method in Java.
Consider visibility and method type differences.
You got /4 concepts.