Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

a question on private instance variable

 
sura watthana
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

looking at the class below


I don't understand how it is possible that p.name can be directly access even though name is a private instance variable.
anyone knows an explanation to this?

thanks

sura
 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Private means private to the class, not to the instance. That means that all code inside the same class (including any enclosing classes if it is an inner class or static nested class) have access to the field.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50217
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob is right, but I would recommend you look for articles about the equals method, because you are not overriding it as you ought to (see Object#equals(java.lang.Object)) but overloading it.

Look for Joshua Bloch's book, or Angelkia Langer's website, or the article W Joe Smith refers to in this thread.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic