java编程求高手 2.定义类Shape和子类Circle、Cylinder.定义类的无参构造函数和有参构造函数,并增加

问题描述:

java编程求高手 2.定义类Shape和子类Circle、Cylinder.定义类的无参构造函数和有参构造函数,并增加相关
1个回答 分类:综合 2014-12-02

问题解答:

我来补答
public class TestShape{
public static void main(String args[]){
Shape s=new Shape();
Circle c=new Circle(5,"yellow");
Cylinder y=new Cylinder ();
System.out.println(s.color);
System.out.println(c.size+" "+c.color+" ");
System.out.println(y.color);
}
}
class Shape{
String color="red";
Shape(){
}
Shape(String color){
this.color=color;
}
}
class Circle extends Shape{
int size;
Circle(){}
Circle(int size,String color){
this.size=size;
this.color=color;
}
}
class Cylinder extends Shape{
int length;
Cylinder (){}
Cylinder (String color,int length){
this.color=color;
this.length=length;
}
}
 
 
展开全文阅读
剩余:2000