Java Private Field Visibility

后端 未结 6 599
轻奢々
轻奢々 2020-12-14 10:05

So I was making a class the other day and used Eclipse\'s method to create the equals method when I realized that it generated the following working code:

6条回答
  •  情书的邮戳
    2020-12-14 10:49

    Mike's quite correct; you are confusing objects (instances of a class) with the class itself. The members are private to the class, not any particular instance of the class.

    I recall being just as surprised about this when I was new to Java.

提交回复
热议问题