Java - PolymorphismWhich of the following is allowed when overriding a method in Java?AChanging the method nameBMaking the method staticCChanging the number of parametersDChanging the return type to a subtype of the original return typeCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand method overriding rulesMethod overriding requires the same method name and parameters. Return type can be a subtype (covariant return type).Step 2: Analyze each optionChanging method name or parameters means overloading, not overriding. Static methods cannot be overridden.Final Answer:Changing the return type to a subtype of the original return type -> Option DQuick Check:Method overriding allows covariant return types = B [OK]Quick Trick: Override must keep name and parameters; return type can be subtype [OK]Common Mistakes:Thinking method name can changeConfusing overriding with overloadingTrying to override static methods
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