suppose A is a base class and B is the derved class. Both
have a method foo which is defined as a virtual method in
the base class. You have a pointer of classs B and you
typecast it to A. Now when you call pointer->foo, which
method gets called?
The next part of the question is, how does the compiler
know which method to call?
Answer Posted / suchi
It depends the pointer points to the object of which class.
If the pointer points to Class A, then the method defined
in class A will be called, and if the pointer points to
class B, then the method defined in class B will be called.
| Is This Answer Correct ? | 2 Yes | 6 No |
Post New Answer View All Answers
What is encapsulation example?
How can you overcome the diamond problem in inheritance?
What is new keyword in oops?
write a program to enter a string like"sunil is a good boy and seeking for a job" not more than 10 characters including space in one line,rest characters should b in other line.if the next line starts from in between the previous word,then print whole word to next line.
How to use CMutex, CSemaphore in VC++ MFC
What is advantage of inheritance?
What is difference between inheritance and polymorphism?
What is balance factor?
What is polymorphism what is it for and how is it used?
What is overloading in oops?
Why interface is used?
write a code for this:trailer recordId contains a value other than 99, then the file must error with the reason ‘Invalid RECORD_ID’(User Defined Exception).
Why is encapsulation used?
What does enum stand for?
Why multiple inheritance is not allowed?