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 different types of JVM's? for example we use dalvik jvm for android then what about the remaining operating systems?
What is overloading and its types?
officer say me - i am offered to a smoking , then what can you say
what's the basic's in dot net
How do you achieve polymorphism?
What is coupling in oop?
What is the highest level of cohesion?
Why do while loop is used?
Why is it so that we can have virtual constructors but we cannot have virtual destructors?
Can we override main method?
class CTest { public: void someMethod() { int nCount = 0; cout << "This is some method --> " << nCount; } }; int main() { CTest *pctest; pctest->someMethod(); return 0; } It will executes the someMethod() and displays the value too. how is it possible with our creating memory for the class . i think iam not creating object for the class. Thanks in Advance... Prakash
What is a class oop?
What is abstraction in oops?
Following are the class specifications: class {int a}; class {int b}; Using friend funtion,calculate the max of two objects and display it.
Can we create object of abstract class?