• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Alex Serna
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21117
32
Eclipse IDE Firefox Browser MySQL Database
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The accessibility options like "private" and "protected" control access at the class level, not at the object level.
 
Alex Serna
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49367
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They are inside the same class, so yes.
 
rahul sengupta
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic