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 the realstic modeling?

1 Answers  


Tell us about yourself.

47 Answers   ABB, Amazon, Fidelity, Flextronics, Franklin Templeton, HCL, Hexaware, IBM, Impetus, Infosys, Reliance, Rofous, Silgate, Sutherland, TCS, Thomson Reuters, Virtusa, Wipro,


Which is the best institute in hyderabad for C/C++ and it also has fast track course structure.

13 Answers   Wipro,


what is oops

4 Answers   DELL,


WHAT IS THE DIFFERENCE BETWEEN ABSTRUCTION AND ENCAPSULATION? PLEASE EXPLAIN IT.

7 Answers   ETH,






Why oops is important?

0 Answers  


Where You Can Use Interface in your Project

0 Answers   KPIT,


What is object and example?

0 Answers  


Write a C++ program to conduct an election of a mayor.Declare a class ELECTION With the following specification: Data member: Name 25 character Age Integer symbol 1 character Member functions: To accept data for 20 contestant To accept symbol as voting from 100 voters. To declare the winner and the loser.

1 Answers   Global Academy, Infotech,


what is static?

4 Answers  


what is the virtual function overhead, and what is it used for ? i hope i can get and appropriate answers, thanks a lot....

6 Answers  


should we use linear search or binary search if elements are placed in random order or mixed?in both cases? i need a little bit detail ans?thnks

2 Answers  


Categories