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 abstraction with example?
What is overriding in oop?
Write a C++ program without using any loop (if, for, while etc) to print prime numbers from 1 to 100 and 100 to 1 (Do not use 200 print statements!!!)
What are the benefits of interface?
What is the fundamental idea of oop?
What is interface in oop?
What is polymorphism what are the different types of polymorphism?
What is constructor in oop?
What is overriding in oops?
What is class and object with example?
what is difference between class template and template class?
What is the advantage of oop over procedural language?
What are the 3 principles of oop?
what type of question are asked in thoughtworks pair programming round ?
What is super in oop?