Private class property visible

Because you are using a copy constructor 😉

More seriously: private variables have class level visibility; your other object is a different instance, but it is of the same class; it is therefore granted that instance members of this object will be visible from the constructor.

Note the “class level”. It means instance variables from inner classes are visible by outer classes, and vice versa:

class A {
    private int a; // instances of B see this

    class B {
        private int b; // instances of A see this
    }
}

Leave a Comment