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 polymorphism and types?
What is class and example?
What is persistence in oop?
Can abstract class have normal methods?
How is class defined?
What is balance factor?
What is encapsulation in ict?
Why is polymorphism needed?
What are the components of marker interface?
IS IT NECESSARY TO INITIALIZE VARIABLE? WHAT IF THE INSTANCE VARIABLE IS DECLARED final ? IS IT NECESSARY TO INITIALIZE THE final VARIABLE AT THE TIME OF THEIR DECLARATION?
What is abstraction with example?
Why interface is used?
what is the 3 types of system development life cycle
What is polymorphism and its types?
• What are the desirable attributes for memory managment?