for example A,B,C,D are class all the 4 class contain one
method who() but the method who() implementaion is differnet
among each class. the relation among the 4 class are
A is base class and is inherited by B and C.and from this
two B and C where D is inherited.
the question is i want to display the output who() method in
all the classes(A,B,C,D)the output of who() method is
diferrent amond all the class(A,B,C,D)
------A------ virtuval who(print a)
override | |
who(print b) B C override who(print c)
| |
-------D------ override who(print d)

Answer Posted / ap

First of the simple cases:

As you mentioned that function "who" in class is virtual and
hence the function from A cannot be executed. I am not sure
but if you try to execute A.who(), it will result in
run-time error.

and if you simply call obj_D.who() you will end up executing
the code defined in who() of class D.

now the slightly tricky one:
In case you want to execute function who() of Class B or C
from an object of type class D then you will have to
typecast the object as Class B or Class C.

I hope this helps.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is abstract thinking intelligence?

797


Why is polymorphism important in oop?

818


What are the types of abstraction?

777


Why it is called runtime polymorphism?

790


What is object in oop with example?

967


What is the real time example of inheritance?

860


What are functions in oop?

787


What is abstract class in oops?

777


Why we use classes in oop?

773


What is an example of genetic polymorphism?

872


How long to learn object oriented programming?

818


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

1986


Whats oop mean?

793


What is encapsulation in simple terms?

772


What are objects in oop?

827