圆:
package test;
public class Circle {
int r;
public Circle(int r) {
this.r=r;
}
public double getarea() {
// TODO Auto-generated method stub
return 3.1415926*r;
}
int r;
public Circle(int r) {
this.r=r;
}
public double getarea() {
// TODO Auto-generated method stub
return 3.1415926*r;
}
}
圆柱:
package test;
public class Cylinder {
Circle bottom;
int height;
Circle bottom;
int height;
public Cylinder(Circle bottom, int height) {
this.bottom = bottom;
this.height = height;
}
public Cylinder(int r, int height) {
this.bottom = new Circle(r);
this.height = height;
}
public double getvolume() {
return height*bottom.getarea();
this.bottom = bottom;
this.height = height;
}
public Cylinder(int r, int height) {
this.bottom = new Circle(r);
this.height = height;
}
public double getvolume() {
return height*bottom.getarea();
}
}
}
A类:
package test;
public class A {
public static void main(String[] args) {
// TODO Auto-generated method stub
Cylinder cylinder=new Cylinder(3,9);
System.out.println(cylinder.getvolume());
// TODO Auto-generated method stub
Cylinder cylinder=new Cylinder(3,9);
System.out.println(cylinder.getvolume());
}
}