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)

Answers were Sorted based on User's Feedback



for example A,B,C,D are class all the 4 class contain one method who() but the method who() impleme..

Answer / ana

only pure virtual function cant be executed, so A.who() can
be executed
and since you override who() in B, C and D, the output is
different

Is This Answer Correct ?    1 Yes 0 No

for example A,B,C,D are class all the 4 class contain one method who() but the method who() impleme..

Answer / 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

More OOPS Interview Questions

What is multilevel inheritance?

0 Answers  


Differences between inline functions and non-inline functions?

4 Answers   Ness Technologies,


You have one base class virtual function how will call that function from derived class?

4 Answers  


what is code for call by value and call by reference?

1 Answers  


What does oop mean in snapchat?

0 Answers  






What is a class and object?

0 Answers  


Input: enter the value:1234 output: 1 2 3 4 write a program to get above output.....

4 Answers   Bally Technologies, IBM, SoftSol,


where is memory for struct allocated? where is memory for class-object allocated? I replied for struct in stack and for class-object in heap. THen he asked if class has struct member variable what happens.class on heap and what about struct in that class? couldnt ans :( :-?

2 Answers   Infosys, Microsoft,


What do you mean by inline function?

6 Answers  


What is this interview room ? Is it a class or an object.

3 Answers   CybAge, NSN, Wipro,


Name a typical usage of polymorphism

3 Answers  


Petrol pump mgt. system: To design a program that display an interface for the sale of the Petrol and then make the entries at the backend in the database.

1 Answers   Wipro,


Categories