My Question :
Suppose

IA--->>>An Interface
             void func();
A---->>>Abstract Class implementing IA
              void func(){}
B---->>Class extending A
           void func(){}
C---->>Class extending B
           void func{}

Now what i am doing .... i made an Object of C class.....

C c = new C();
IA ia = c;

now if i want to call ....

ia.func();

which function will be called......

i want to call func() of B class ......
whether i have to typecast the interface for that....any other solution....or it is some what wrong implementation....Solutions are welcome....

It will call the function (method) in C.
You can cast to type B to call B's implementation.

Maybe I don't understand your hierarchy, but I believe you can also use super.methodName() to call the superclass's method instead of the class's method.

Maybe I don't understand your hierarchy, but I believe you can also use super.methodName() to call the superclass's method instead of the class's method.

But what if all the functions of all classes having same name have different implementation....

I answered your actual question earlier, but on further thought I'm puzzled as to why you would want to do that.
If C is a kind of B that needs different implementations of various methods, why create a C then decide to use the "wrong" methods for it? At first sight this looks like a design error, but maybe you have a good reason?

I answered your actual question earlier, but on further thought I'm puzzled as to why you would want to do that.
If C is a kind of B that needs different implementations of various methods, why create a C then decide to use the "wrong" methods for it? At first sight this looks like a design error, but maybe you have a good reason?

I am not allowed to change or add any function in any class rather you can create new class or extend it with any class.......I create that C class......Till B class it was earlier design...also requirement is not to change the name of functions....So this is the only way for me......
for now in this rather than casting i got a new idea....
in C---->func()
if(conditionApplied)
doMineWork
else
super.func();


So now existing app will be work and mine too :).....

OK. Your latest solution is a pretty standard way of doing things. Shouldn't be a problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.