What is method overriding in Java?

Java MCQ: What is method overriding in Java?

a) Defining a method with the same name and parameters in a subclass
b) Defining a method with a different name
c) Defining multiple methods in a class
d) Defining a method with the same name but different parameters

Answer:

a) Defining a method with the same name and parameters in a subclass

Explanation:

Method overriding in Java occurs when a subclass provides a specific implementation for a method that is already defined in its superclass. The overridden method in the subclass must have the same name, return type, and parameter list as the method in the superclass.

Understanding method overriding is crucial for creating flexible and dynamic code in Java, particularly in object-oriented designs where inheritance is used.

Reference links:

https://www.rameshfadatare.com/learn-java-programming/
https://www.javaguides.net/p/java-tutorial-learn-java-programming.html

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top