public class Circle {
private int radius;
public Circle(int r){
radius=r;
}
public double getArea(){
return Math.PI*Math.pow(radius, 2);
}
public class Cylinder {
private Circle circle;
private int height;
public Cylinder(int r,int h){
Circle circle=new Circle(r);
height=h;
}
public double getVolume(){
return Math.PI*Math.pow(radius, 2)*height;
}
}
}
public class Test {
public static void main(String[] args) {
Cylinder c1=new Cylinder(5,5);//为什么这样不行??
System.out.println();
}
}
我试了下,还是不行,在Circle c =new Circle();报错了,Circle类中构造方法Circle是有参数的吧 ------其他解决方案--------------------
package com.briup.test08;
public class Test {
public static void main(String[] args) {
//Cylinder c1=new Cylinder(5,5););//为什么这样不行??
//是可以的,改成下面这样就行了
Circle c =new Circle(5);
Circle.Cylinder cy=c.new Cylinder(5,5);
}
}