Module: | Core Architecture, Basics & Control Flow
Q23: Consider the following statements regarding access modifiers and exceptions during overriding:
1. When overriding a parent method, the child class method is strictly prohibited from utilizing an access modifier that is more restrictive than the original parent method's modifier.
2. An overridden method in a subclass is legally permitted to throw new or broader checked exceptions that were never declared in the parent class method's signature.
3. If a parent class method is declared with a protected access modifier, the overriding subclass method can legally elevate its visibility by declaring it as public.
Which of the above statements is/are correct?
2. An overridden method in a subclass is legally permitted to throw new or broader checked exceptions that were never declared in the parent class method's signature.
3. If a parent class method is declared with a protected access modifier, the overriding subclass method can legally elevate its visibility by declaring it as public.
Which of the above statements is/are correct?
✅ Correct Answer: B
🎯 Quick Answer:
The correct combination is 1 and 3. Statement 2 is incorrect because overriding rules strictly dictate that a subclass method cannot throw new or broader checked exceptions, as this would violate the established error-handling contract of the parent class.Structural Breakdown: Visibility can be expanded but never compressed.
Checked exceptions can be narrowed or entirely eliminated, but never broadened.
Historical/Related Context: These strict rules enforce the Liskov Substitution Principle from the SOLID design paradigm.
If a legacy system expects a parent object that throws an IOException, silently substituting a child object that suddenly throws a broader, unhandled Exception would instantaneously crash the system.
Causal Reasoning: Reducing visibility is prohibited because polymorphism relies on the parent's contract.
If a parent declares a method as public, external classes expect universal access.
If a subclass hid that method by making it private, any polymorphic call attempting to access it would trigger a fatal runtime failure.