参照教材例6.1,定义Point(点)类,由Point类派生出Circle(圆)类,再由Circle类派生出Cylinder(圆柱体
1个回答
展开全部
public class Point2 {//瞎弄的几个 我们的书不一样。
int x,y;
public Point2(int a,int b){
x = a;
y = b;
}
public String toString(){
return "("+x+","+y+")";
}
public static void main(String args[]){
Point2 p[] = new Point2[3];
p[0] = new Point2(0,0);
p[1] = new Circle3(0,0,4);
p[2] = new Cylinder(0,0,4,5);
for(int i = 0; i<3; i++){
System.out.println(p[i].toString());
}
}
}
class Circle3 extends Point2{
int r;
public Circle3(int x,int y,int a){
super(x,y);
r = a;
}
public float getArea(){
return (float)(Math.PI*r*r);
}
}
class Cylinder extends Point2{
int h,r;
public Cylinder(int x,int y,int a,int b){
super(x,y);
h = a;
r = b;
}
public float getV(){
return (float)(Math.PI*r*r*h);
}
}
int x,y;
public Point2(int a,int b){
x = a;
y = b;
}
public String toString(){
return "("+x+","+y+")";
}
public static void main(String args[]){
Point2 p[] = new Point2[3];
p[0] = new Point2(0,0);
p[1] = new Circle3(0,0,4);
p[2] = new Cylinder(0,0,4,5);
for(int i = 0; i<3; i++){
System.out.println(p[i].toString());
}
}
}
class Circle3 extends Point2{
int r;
public Circle3(int x,int y,int a){
super(x,y);
r = a;
}
public float getArea(){
return (float)(Math.PI*r*r);
}
}
class Cylinder extends Point2{
int h,r;
public Cylinder(int x,int y,int a,int b){
super(x,y);
h = a;
r = b;
}
public float getV(){
return (float)(Math.PI*r*r*h);
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询