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 are the ways in which a constructors can be called?
Do you know about multiple inheritance?
What are the 4 pillars of oop?
Write a program to reverse a string using recursive function?
What is object in oop?
Can we have inheritance without polymorphism?
What is overriding vs overloading?
Why do we use oop?
How do you use inheritance in unity?
What is class encapsulation?
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.
How is class defined?
What is polymorphism what is it for and how is it used?
What is object and class in oops?
They started with the brief introduction followed by few basic C++ questions on polumorphism, inheritance and then virtual functions. What is polymorphims? How you will access polymorphic functions in C? How virtual function mechanism works?