the point here is class C inherits the method show() from class B. and second point is call to a method depends on the actual object in the reference at runtime (but plz make a note the method declaration should also exist in the reference type orelse it will give compilation error).
so here a and b references have C object so the ouput will be B followed by B b'coz the method in class B which is inherited by class C and is called at runtime.
>>B b = new C(); >>b.show(); The method invocation depends on the type of object stored rather than the variable type B.So in the above code B b = new C(), the compiler will first look for the presence of show() method in Class C,if it doesn't finds it, it starts searching in the parent class. So u get B printed in this case.
A a = new C(); a.show(); In this case also samething happens , the search doesn't depend on variable stored but the type of object referred.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com