Private Member Access Java

后端 未结 7 2273
盖世英雄少女心
盖世英雄少女心 2020-12-05 16:29

Is the private member access at the class level or at the object level. If it is at the object level, then the following code should not compile

    class Pr         


        
7条回答
  •  青春惊慌失措
    2020-12-05 17:23

    Just to add to DevSolar's answer, I would expect messWithI to be declared static as such:

    public static void messWithI(PrivateMember t) {
      t.i *= 2;
    

    } I had a hard time even reading what it is that you were trying to do without the 'static' hint... And it also makes it easier to answer your original question -- which is that private members are not limited in scope to just the instance in question.

提交回复
热议问题