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

Question: Write a program that prints a paycheck. Ask the program user for the name of the employee, the hourly rate, and the number of hours worked. If the number of hours exceeds 40, the employee is paid “time and a half”, that is, 150 percent of the hourly rate on the hours exceeding 40. Be sure to use stepwi se refine ment and break your solution into several functions. Use the int_name function to print the dollar amount of the check.

703


• What are the desirable attributes for memory managment?

1731


What are the three parts of a simple empty class?

1462


How do you achieve runtime polymorphism?

573


What is the difference between encapsulation and polymorphism?

598






What is polymorphism and why is it important?

562


Write a c++ program to display pass and fail for three student using static member function

2820


Why do we use oop?

607


Why polymorphism is used in oops?

586


Are polymorphisms mutations?

705


write a program to find 2^n+1 ?

1555


What are functions in oop?

586


What is abstraction with example?

609


What is interface? When and where is it used?

1666


What does I oop mean?

618