Java - PolymorphismWhich of the following statements about method overriding in Java is correct?AStatic methods can be overriddenBOverriding methods must have the same or narrower access modifierCOverriding methods can throw new checked exceptions not declared in the parent methodDReturn type of overriding method can be a subtype of the original method's return typeCheck Answer
Step-by-Step SolutionSolution:Step 1: Review exception rules in overridingOverriding methods cannot throw new or broader checked exceptions.Step 2: Review access modifier rulesOverriding method must have same or wider (not narrower) access.Step 3: Review return type and static method rulesReturn type can be subtype (covariant). Static methods cannot be overridden, only hidden.Final Answer:Return type of overriding method can be a subtype of the original method's return type -> Option DQuick Check:Covariant return types allowed in overriding = A [OK]Quick Trick: Overriding allows covariant return types, not new checked exceptions [OK]Common Mistakes:Thinking new checked exceptions allowedAssuming narrower access modifier allowedConfusing static method hiding with overriding
Master "Polymorphism" in Java9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Java Quizzes Abstraction - Partial abstraction - Quiz 9hard Classes and Objects - Object lifecycle - Quiz 1easy Classes and Objects - Instance variables - Quiz 4medium Constructors - Constructor overloading - Quiz 2easy Custom Exceptions - Throwing custom exceptions - Quiz 5medium Encapsulation - Why encapsulation is required - Quiz 8hard Exception Handling - Throws keyword - Quiz 7medium Exception Handling - Checked vs unchecked exceptions - Quiz 5medium Object-Oriented Programming Concepts - Procedural vs OOP approach - Quiz 13medium Polymorphism - Upcasting and downcasting - Quiz 4medium