aspose file tools*
The moose likes Beginning Java and the fly likes Why can I have access to the objects private property from another object? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why can I have access to the objects private property from another object?" Watch "Why can I have access to the objects private property from another object?" New topic
Author

Why can I have access to the objects private property from another object?

Alex Serna
Ranch Hand

Joined: Sep 18, 2009
Posts: 58
Hello,

My java skills have gotten a little rusty... could anyone please tell me why I can access the property "text" which is marked private from within the equals method? If the object "other" is a different object, shouldn't I be using an accessor method to access it's private properties?



Thanks.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18563
    
    8

The accessibility options like "private" and "protected" control access at the class level, not at the object level.
Alex Serna
Ranch Hand

Joined: Sep 18, 2009
Posts: 58
Thank you for the response. So if I have a component object of the same class as the the main class, that means that from the main class I can have access to all the component object's properties even if they are private. Right?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Alex Serna wrote:Thank you for the response. So if I have a component object of the same class as the the main class, that means that from the main class I can have access to all the component object's properties even if they are private. Right?


Well, you already have an answer that you apparently think tells you that. Why not write some code and try it? How much confirmation do you need?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38729
    
  23
They are inside the same class, so yes.
rahul sengupta
Greenhorn

Joined: Aug 25, 2011
Posts: 8
Access specifiers actually work with respect to classes.
So if we assign something private, it means that only within that class that member can be accessed and outside it, not.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why can I have access to the objects private property from another object?