All Exams Test series for 1 year @ ₹349 only
Question

When a method in a subclass has the same name and type signatures as a method in the superclass, then the method in the subclass _____ the method in the superclass.

The correct answer is
Overrides

The question describes a situation in object-oriented programming where a method in a child class (subclass) has the exact same name and parameter list (type signatures) as a method in its parent class (superclass).

Method Overriding Concept

When a subclass provides a specific implementation for a method that is already defined in its superclass, this is known as method overriding.

  • The method in the subclass must have the same name as the superclass method.
  • The method in the subclass must have the same parameter list (type signatures) as the superclass method.
  • The subclass method allows you to change the behavior inherited from the superclass.

Why Other Options Are Incorrect

  • Overloading: Method overloading occurs when multiple methods in the *same class* have the same name but different parameter lists (signatures). This is different from the scenario described.
  • Inherits: While the subclass does inherit methods from the superclass, the term 'inherits' doesn't specifically describe the action of providing a new implementation for a method with the same signature. Overriding is a more precise term for this specific relationship.
  • Friendships: This is not a standard term used in object-oriented programming to describe the relationship between subclass and superclass methods.

Conclusion

Therefore, when a subclass method has the same name and type signatures as a superclass method, it overrides the superclass method.

Was this answer helpful?

Important Questions from OOPs concept

  1. Which among the following best describes polymorphism ?
  2. Which operator is used for dynamic memory allocation in C++?

  3. Which one of the following is correct, when a class grants friend status to another class ?
  4. Which statements is correct regarding main () function in C++?

    I. It is a user defined function.

    II. It is a pre-defined function.

  5. Consider the following segment of C++ code.

    int j, n;

    for(j=1;j<=n; )

    j=j*2;

    What is the number of comparisons made in the execution of the loop for any n > 0?

Need Expert Advice?

Start Your Preparation with Prepp Mobile App

Download the app from Google Play & App Store
Download the app from Google Play & App Store
Prepp Mobile App