From page 546 on the SCJP Study Guide. I seem to be able to access the private property "moofValue" directly in the equals method without having to HAVE TO use the getMoofValue() getter method. Why is this?
"private" means "accessible only from within the same class". In this example you're accessing it from within the Moof class, so there's no restriction.
Joined: Jan 24, 2012
This means, I guess, that even when the object involved is not the "this" object, but is an argument object "Moof o" that is passed into the equals method, you can still access the argument "Moof o"s properties directly as we are "inside" the Moof class.
Detlef Boehm wrote:isn't it also, because the overridden equals() method is public!? And it has to be public, regarding the rules for overriding.
No, it's nothing to do with that. You're right that the equals() method has to be public because it's overriding a public method; but the visibility of the method doesn't affect what the code inside that method can access, it only affects whether other code can access that method.