This code woun't compile, first and formost, since the method invokation show(null) is ambiguous. You would either have to use show((CA) null) or show((CB) null). Then, the implementation executed will be that from CB, so the output will be "... of CB". What the dots become depends on the typecast you insert, see above.
Hope that helps, Guido
Ravi Bhushan Ratnakar
Joined: Apr 14, 2008
Sorry to say, but there isn't any compilation error. I am using jdk1.6 update 5 version
The explanation is very simple for this problem. Since you are assigning sub class instance to superclass reference, and calling a method which is overridden by subclass, the sub class method will be called since the actual instance is of sub class. Next is passing null to method now as other rauncher rightly mentioned, passing null will call the most specific method of that object. Since there are two methos one takes the argument of super class and other takes the argument of sub class , subclass method will be called because it is more specific. Hence CB of CB will be the output.
thanks & regards,<br />Anuj Bhatnagar
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