annamalai bala wrote:Ankit Your website seems to be down for more than aweek any problem and when can i access it???
Please refrain from starting personal talks in the forum. You can send me a personal message for things like this. I'm working on a different site right now that will replace the current one...
You've sent me on email that the output was "result of A:30" which is quite clear to me. The two add methods are overloaded, and since you didn't provide any arguments, so the add method of class A was called...
i thought instance variables can not be overridden...and since they are not inside a method, this is not shadowing as well.
So, why is it not giving compilation time error?
Instance variables can be shadowed in a inheritance hierarchy. What is important to understand here is that variable references are resolved at compile-time and method invocations resolved at run time.
In this case if you do:
you will get:
result of A:30
if you do:
you will get:
result of B:300
because code executing within b will see the a and b shadowing the corresponding vars in the superclass a.
SCJP 1.4 and 6.0, SCJD
Don't get me started about those stupid light bulbs.