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. Match List I with List II

    List IList II
    (Programming Paradigm)(Characteristic)
    A.ImperativeI.Declarative, clausal representation, theorem proving
    B.Object‐orientedII.Side‐effect free, declarative, expression evaluation
    C.LogicIII. Imperative, abstract data type
    D.FunctionalIV.Command‐based, procedural

    Choose the correct answer from the options given below :

  2. Let A be the base class in C++ and B be the derived class from A with protected inheritance. Which of the following statement is false for class B?

  3. A member function can always access the data in _______, (in C++).

  4. Which of the following is not correct for virtual function in C++?

  5. Which of the following is correct (in C++)?

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