package generations;

        // An illustration of the `protected' access modifier.
        // Child extends Parent which extends Grandparent.
        // Child and Parent have access to the public and protected
        // elements of their super classes, but not their private
        // elements.
class ProtectedMain {
    public static void main(String[] args) {
        Child c = new Child();
        c.setBottom(24);
        System.out.println(c.getBottom()+" "+c.getMiddle()+" "+
                                c.getTop());
    }
}

class Grandparent {
    public int getTop(){
        return top;
    }

    void setTop(int newTop){
        top = newTop;
    }

    private int top;
}

class Parent extends Grandparent {
    public int getMiddle(){
        return middle;
    }

    protected void setMiddle(int newMiddle){
        middle = newMiddle;
    }

    private int middle;
}

class Child extends Parent {
    public int getBottom(){
        return bottom;
    }

    public void setBottom(int newBottom){
        bottom = newBottom;
        setMiddle(bottom/2);
        setTop(bottom/3);
    }

    private int bottom;
}
