Multiple choice

What will happen if the derived class and the base class contain a member with the same name?

  1. The compiler will show an error when the code is compiled.

  2. The dervied class member will hide the defintion of the base class member.

  3. The base class member will be called even with the child class object.

  4. Only child class member will be called irrespective of the object.

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

If the derived class and the base class contain a member with the same name, it is called 'Member Overriding'. For example, there is a class named 'A', which has a function named 'show()'. If we declare a child class of 'A' named 'B' and declare a function with the same name show () in B, the show() declared in B will hide the show() declared in A. If an object of class B' makes a call of show() , the one defined in the child class(B) will be processed. If an object of the base class makes a call to show(), then the one defined in the base class will be called.