access of protected field from other class
<p>For the below code, I can access the protected fields of a <code>SeatPlan</code> class and change its value from the <code>Classroom</code> class, which looks like not secure for those data.</p>

<p>Is this normal? Isn't it protected fields can be accessed by its subclass only? Otherwise I need to change them to <code>private</code> field?</p>

<hr>

<p>Let's say I have an <code>abstract</code> class with <code>protected</code> fields:</p>

<pre><code>public abstract class SeatPlan {
    protected int rowNum;
    protected int columnNum;

    public abstract void method();
}
</code></pre>

<p>Then it has child classes:</p>

<pre><code>public class ASeatPlan extends SeatPlan {
    public ASeatPlan(){            // constructor
        this.rowNum= 10; 
        this.columnNum = 7;
    }
    // omitted code
}

public class BSeatPlan extends SeatPlan {
    public BSeatPlan(){            // constructor
        this.rowNum= 7;
        this.columnNum = 15;
    }
    // omitted code
}
</code></pre>

<p>A class <code>Room</code> contains a <code>private</code> field of <code>SeatPlan</code> object:</p>

<pre><code>public class Room {
    private SeatPlan seatPlan;

    public Room(SeatPlan seatPlan){       // constructor
        this.seatPlan = seatPlan;
    }

    public SeatPlan getSeatPlan(){     // getter method
        return seatPlan;
    }

    //omitted code
}

public class Classroom {
    public SeatPlan doSomething(Room room){
        SeatPlan seats = Room.getSeatPlan();
        seats.rowNum = 99999;     &lt;--------------- accidentally change the value ------

    //omitted code
    }
</code></pre>