Circle类
package bzu.info.software;
public class Circle {
private static final double PI = 3.14;
int r;//半径
public Circle(int r){
this.r=r;
}
public double getMj(){
return r*r*PI;
}
}
cylinder类
package bzu.info.com;
import bzu.info.software.*;
public class Cylinder {
Circle bottom;
int height;
Cylinder(Circle bottom,int height){
this.bottom=bottom;
this.height=height;
}
Cylinder(int r,int height){
this.bottom=new Circle(r);
this.height = height;
}
public double getvolume() {
return height*bottom.getMj();
}
}
A 类
package bzu.info.com;
import bzu.info.software.Circle;
public class A {
public static void main(String[] args) {
// TODO Auto-generated method stub
Circle cc=new Circle(5);
Cylinder c=new Cylinder(5, 2);
double s=c.getvolume();
System.out.println("体积为"+s);
}
}