If i want to report a bug

Mhh, I misunderstood the JLS earlier in this thread. The relevant piece actually is this, the second paragraph of 6.6:

Note that accessibility is a static property that can be determined at compile time; it depends only on types and declaration modifiers.

With other words, accessibility is determined by the compile time type of the reference, not by runtime type of the object.

So it's working as specified. And I stand to my point that it needs to work that way to conform to the Liskov Substitution Principle.

Personally, I think the actual design error is that protected methods can be called from outside the inheritance hierarchy at all. Your mileage may vary, of course.

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus

Actually what's happening when assigning the horse object to animal reference. What is the difference bw the reference and object.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 44016

33

posted Jun 02, 2008 06:39:00

0

"Ganesan" when you logged in first, you appear to have missed the naming policy which requires first name-space-last name. Please go to "my profile" and correct your displayed name to comply.

CR

Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112

posted Jun 02, 2008 14:02:00

0

Originally posted by ganzan Ramakrishnan: Hi,

Actually what's happening when assigning the horse object to animal reference. What is the difference bw the reference and object.

The only difference is that h is of type Horse, and a is of type Animal. The compiler doesn't even look at the assignments when determining whether you are allowed to call the eat method - in this regard, they are totally irrelevant.

Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112

posted Jun 02, 2008 14:02:00

0

Originally posted by ganzan Ramakrishnan: Hi,

Actually what's happening when assigning the horse object to animal reference. What is the difference bw the reference and object.

The only difference is that h is of type Horse, and a is of type Animal. The compiler doesn't even look at the assignments when determining whether you are allowed to call the eat method - in this regard, they are totally irrelevant.