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. 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?

  2. Which of the following statements are true regarding C++?

    (a) Overloading a function gives the capability to an existing operator to operate on other data types.

    (b) Inheritance in object-oriented programming provides support to reusability.

    (c) When object of a derived class is defined, first the constructor of derived class is executed then constructor of a base class is executed.

    (d) Overloading is a type of polymorphism.

    Choose the correct option from those given below:
  3. 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 :

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

  5. Which of the following is not correct for virtual function 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