Monday, 30 September 2013

Variable access to private class

Variable access to private class

I came across code like this earlier today:
public class MyThing {
ArrayList<String> myStrings = new ArrayList<String>();
MyPrivateClass mpc = new MyPrivateClass();
public void DoWork() {
mpc.DoStuff();
}
class MyPrivateClass {
void DoStuff() {
myStrings.add("Test");
}
}
}
How or why does this work? How does MyPrivateClass have access to the
instance of myStrings without a reference to the class which created it?

No comments:

Post a Comment