Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

private variable scope

 
Salil Vverma
Ranch Hand
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code attached below works fine and prints true which is fine but I could not understand why there was no compilation error on the equals function while it was trying to access the private member of another object. Could you please help me understanding this,
 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The equals method is accessing private member on an instance of its own class. This is allowed. The members of the class have access to private members of objects of their own class...
 
suman mitragupta
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
private varibale with object instance is ok.
 
Atwal Usha
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the private member is used within the class and it is allowed. There would have been compiler error if it would have been used outside the class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic