Introduction / Context:
This evaluates the rules of overriding regarding access modifiers, return types, and static usage in Java.
Concept / Approach:
- Overridden methods can increase visibility (protected → public is valid).
- Return type must be the same or covariant; short is not covariant with int.
- Overridden methods cannot be static if the original was not static.
- Access cannot be reduced (protected → private is invalid).
Step-by-Step:
Option A: Valid override (protected → public, same return type).Option B: Invalid (reduces visibility).Option C: Invalid (return type mismatch).Option D: Invalid (adds static to non-static method).
Final Answer:
public int method1(int a, int b) { return 0; }
Discussion & Comments