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

Which language is not a true object oriented programming language?

904


What is Difeerence between List obj=new ArrayList(); and ArrayList obj=new ArrayList()?

2328


What is polymorphism give a real life example?

789


write string class as your own class in java without using any built-in function

2241


What are the benefits of oop?

901


can inline function declare in private part of class?

4019


What is for loop and its syntax?

827


How is polymorphism achieved?

791


what is graphics

2232


How Do you Code Composition and Aggregation in C++ ?

24782


What is the important feature of inheritance?

886


What is class encapsulation?

854


Who invented oop?

868


What does and I oop mean in text?

881


Why is static class not inherited?

856