Why Java is Not My Favorite Language — Reason #36

Member access modifiers apply that the class level not the object level. For example, the following perfectly legal in Java.

class Foo
{
    private String name;

    public String someOneElsesName(Foo another)
    {
        return another.name;
    }
}

The method someOneElsesName() returns the value of a private instance variable of an object that is not one on which the method was executed. This is suppose to promote good encapsulation?

Comments 5