C++ Programming - OOPS Concepts - Discussion

Discussion Forum : OOPS Concepts - General Questions (Q.No. 38)
38.
What happens if the base and derived class contains definition of a function with same prototype?
Compiler reports an error on compilation.
Only base class function will get called irrespective of object.
Only derived class function will get called irrespective of object.
Base class object will call base class function and derived class object will call derived class function.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
22 comments Page 1 of 3.

Vishal Tavande said:   1 decade ago
Only base class function will get called irrespective of object. As I tried this at my desk.

Dhanesh ful said:   1 decade ago
This example of method overrding only the the method of derived class is call istead of base class.

Sona said:   1 decade ago
The answer given is right as it totally depends on calling class object.

Mohit said:   1 decade ago
The correct answer is B.

If you call function with derived class object it calls base class function.

To prevent this you have to use virtual function concept.

Sonu said:   1 decade ago
I am confused about objects but yes when we use base class pointer base class function is called irrespective of the address to which it is pointing to.

Shraddha said:   1 decade ago
Only base class constructor is called.

Pallavi said:   1 decade ago
We can declare both base & derived class objects and as per that we can directly call the functions of that class.

Abdul Rizwan said:   1 decade ago
Ya ! answer is B only.

Base class method will call all the time even we are calling derived class method so to reduce this problem we need to use Virtual function concept.

Yogita said:   1 decade ago
I also agree with option B because both class contain same prototype. Prefrence gives to base class.

Pooja said:   1 decade ago
It will raised an ambiguity error cause compiler will confused when we create the object of derived class.


Post your comments here:

Your comments will be displayed after verification.