我知道私有变量不是继承的,所以如何在我的子类中获得对它的访问?
即
class A{
private int i = 5;
// more code
}
class B extends A{
public int toInt(){
return super.i;
}
}
Run Code Online (Sandbox Code Playgroud) 我必须为打印出形状的抽象父类创建子类,但每当我尝试创建一个对象时,它一直告诉我我无法实例化一个抽象类,当我abstract从我的代码中删除该关键字时,它会覆盖,它说我也不能这样做.
请帮忙!
我的代码:
public class Rectangle extends VectorObject {
protected int ID, x, y, xlnth, ylnth;
protected int matrix[][];
Rectangle(int id, int ax, int ay, int xlen, int ylen) {
super(id, ax, ay);
xlnth = xlen;
ylnth = ylen;
}
public int getId() {
return ID;
}
public void draw() {
String [][] matrix = new String[20][20];
for (int i = 0; i < 20; i++) {
for (int j = 0; j < 20; j++) {
if …Run Code Online (Sandbox Code Playgroud)