Recall & Review
beginner
What is method overriding in Java?
Method overriding occurs when a subclass provides its own version of a method that is already defined in its superclass. It allows the subclass to change or extend the behavior of that method.Click to reveal answer
intermediate
What are the rules for method overriding in Java?
The method in the subclass must have the same name, return type, and parameters as the method in the superclass. The overriding method cannot have more restrictive access than the overridden method.Click to reveal answer
beginner
Can a private method be overridden in Java?
No, private methods cannot be overridden because they are not visible to subclasses. They are only accessible within the class they are declared in.Click to reveal answer
beginner
What is the use of the @Override annotation?
The @Override annotation tells the compiler that the method is intended to override a method in the superclass. It helps catch errors if the method does not correctly override any method.
Click to reveal answer
intermediate
What happens if you call an overridden method on a superclass reference pointing to a subclass object?The subclass's version of the method is called. This is called dynamic method dispatch and supports runtime polymorphism.
Click to reveal answer
Which of the following is true about method overriding?
✗ Incorrect
Method overriding requires the subclass method to have the same name, parameters, and return type as the superclass method.
What does the @Override annotation do?
✗ Incorrect
The @Override annotation helps the compiler check that the method correctly overrides a method from the superclass.
If a superclass reference points to a subclass object, which method is called when invoking an overridden method?
✗ Incorrect
Java uses dynamic method dispatch to call the subclass's overridden method at runtime.
Can a subclass override a static method from its superclass?
✗ Incorrect
Static methods belong to the class, not instances, so they cannot be overridden but can be hidden by a subclass static method.
Which access modifier is NOT allowed for an overriding method compared to the overridden method?
✗ Incorrect
The overriding method cannot have more restrictive access than the overridden method to maintain accessibility.
Explain method overriding and why it is useful in Java.
Think about how subclasses can change what a method does.
You got /4 concepts.
Describe the rules and restrictions when overriding a method in Java.
Focus on what must stay the same and what cannot be changed.
You got /4 concepts.