I am creating a class named MyList, and declare all instance variables to be private. In my client code class here named "MyListClient", I declared object list1, of course, MyListClient cannot directly access to private instance variable size by list1.size, the only way I can do is by calling method list1.size().
However, in the implementation class named "MyList", for the method addAll, why can I access to another object's private instance variable. I attached screenshot here, in the addAll method, "other" is the different object of the same class "MyList". But I can write code, like "other.size" or "other.elementData", there are no error happened. Do I miss something? I think you cannot access to another object's private instance variable, but here you can. In the client code class, "List1" is also the different object of same class MyList, which cannot write like "list1.size", I am so confused.
I thought it is wrong to write code like "other.size" and "other.elementData", the error should happen. However it is correct code. I cannot understand why