Java private field access.

package space.yuanjiang.java;

public class PrivateFieldsAccess {
    private String name;
    private Integer age;

    public PrivateFieldsAccess(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    public int compare(PrivateFieldsAccess other) {
        // private fields can be accessed within the class itself
        // even when the private fields belong to other instances
        return this.age.compareTo(other.age);
    }
}
TOPâ–˛
Post tagged with: java