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


Please Help Members By Posting Answers For Below Questions

What is polymorphism and types?

594


What is class and example?

561


What is persistence in oop?

658


Can abstract class have normal methods?

602


How is class defined?

574






What is balance factor?

576


What is encapsulation in ict?

597


Why is polymorphism needed?

585


What are the components of marker interface?

598


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?

1570


What is abstraction with example?

597


Why interface is used?

547


what is the 3 types of system development life cycle

2429


What is polymorphism and its types?

587


• What are the desirable attributes for memory managment?

1720