简体   繁体   English

父抽象类中的变量是否被子类继承?

[英]Do variables in a parent abstract class get inherited by the child class?

Okay so will each instance of a subclass ie a J_Tetrimino class which extends Tetrimino get its own int[][] UP and String orientation? 好的,那么子类的每个实例(即扩展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;
}

Yes. 是。 Every instance of a concrete implementation of your posted abstract class will get its' own instance of those fields. 发布的抽象类的具体实现的每个实例都将获得这些字段的自己的实例。 None of them are static which would make them shared. 它们都不是static ,这会使它们共享。 Also, all of them are protected so they will be visible in the sub-class (unless they're shadowed). 而且,所有它们都protected因此它们将在子类中可见(除非已被阴影化)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM