Hi kiran madhan,
First of all, a warm welcome to CodeRanch!
kiran madhan wrote:System.out.println(b.i) is not accessing -1 but accessing 99 from base class...!
What would be the reason...But it is accessing method properly...?
Here are two very simple (and hopefully easy to remember) but
very, very, very important rules (which you must know by heart):
Which instance variables you can access is determined at compile time based on the reference variable type.Which instance methods you can call/invoke is determined at compile time based on the reference variable type. Which instance method is actually executed is decided at runtime based on the type of the actual object (= polymorphism).
Hope it helps!
Kind regards,
Roel