java 定义2个类 一个父类Shape 子类Triangle 我Shape Triangle=new Triangle();在调用子类的方法不能用
父类//publicabstractclassShape{privateStringcolor;publicShape(){}publicShape(Stringcolo...
父类//
public abstract class Shape {
private String color;
public Shape() {
}
public Shape(String color) {
super();
this.color = color;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
// 定义形状
public abstract void getType();
//子类三角
public class Triangle extends Shape {
public Triangle(String color, int a, int b, int c) {
super(color);
this.a = a;
this.b = b;
this.c = c;
}
// 三角形的三边
int a;
int b;
int c;
public boolean setSides() {
if (a + b > c) {
return true;
}
if (a + c > b) {
return true;
}
return false;
}
是不是抽象类不能实例化啊 那我要改怎么改 要用子类实例化吗 展开
public abstract class Shape {
private String color;
public Shape() {
}
public Shape(String color) {
super();
this.color = color;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
// 定义形状
public abstract void getType();
//子类三角
public class Triangle extends Shape {
public Triangle(String color, int a, int b, int c) {
super(color);
this.a = a;
this.b = b;
this.c = c;
}
// 三角形的三边
int a;
int b;
int c;
public boolean setSides() {
if (a + b > c) {
return true;
}
if (a + c > b) {
return true;
}
return false;
}
是不是抽象类不能实例化啊 那我要改怎么改 要用子类实例化吗 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询