Java private field access possible when having a reference?

前端 未结 7 1345
野性不改
野性不改 2020-12-19 03:12

I came across the following \"strange\" feature today - if you have a reference to an object from the class A in the body of the class A you can access the private fields of

7条回答
  •  有刺的猬
    2020-12-19 03:49

    Those keywords are class-oriented, not object-oriented. So it just looks and sees "oh huh, an object of class Foo is trying to access a private object on Foo. Well, that's fine".

提交回复
热议问题