父级抽象类中的变量是否由子类继承?
问题描述:
好,那么子类的每个实例,也就是扩展了Tetrimino的J_Tetrimino类,都会得到它自己的int [] [] UP和String方向?父级抽象类中的变量是否由子类继承?
public abstract class Tetrimino {
// [row][col]
/*The size of the area a tetrimino needs*/
protected final int TETRIMINO_SPACE_SIZE = 3;
/*The upwards and initial orientation of the J tetrimino*/
protected int[][] UP;
/*The left and second orientation of the J tetrimino*/
protected int[][] LEFT;
/*The down and third orientation of the J tetrimino*/
protected int[][] DOWN;
/*The right and fourth orientation of the J tetrimino*/
protected int[][] RIGHT;
protected String orientation = "UP";
public String getCurrentOrientation() {
return orientation;
}
答
是的。您发布的抽象类的具体实现的每个实例都将获得它自己的这些字段的实例。他们都不是static
这将使他们共享。此外,它们全都是protected
,所以它们将在子类中可见(除非它们被遮蔽)。
感谢这正是我想知道的! – 2014-08-29 03:20:38