Question

A virtual function is called using a reference to a base class. Discuss if the function...

A virtual function is called using a reference to a base class. Discuss if the function in base class is called or the function in the derived class and why?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

That's called polymorphism

case 1)
if the base class pointer is pointing to an object of the base class, then the function in the base class is called

case 2)
if the base class pointer is pointing to an object of the derived class, and if this virtual function is not overriden in the derived class, then the function in the base class is called

case 3)
if the base class pointer is pointing to an object of the derived class, and if this virtual function is overriden in the derived class, then the function in the derived class is called

This is how polymorphism works..
Add a comment
Know the answer?
Add Answer to:
A virtual function is called using a reference to a base class. Discuss if the function...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT