/* 編寫一個圓柱體類Cylinder,擁有:?@兩個成員變量? double h(私有,浮點); ?//圓柱體的高;? double r(私有,浮點); ?//圓柱體的半徑;??@構造方法? Cylider(double r,double h) //創建Circle對象時將半徑初始化為r???@成員方法? double getVolume() ?//獲取圓柱體的高? void showVolume() ? //將圓柱體的體積輸出到屏幕*/public class ?Cylinder { private double h=3; ? private double r=2;? ? Cylinder(){? ? ? ? System.out.println(r*r*3.14*h);? ? }? ? double getVolume(double a){? ? ? ? return h;? ? }? ? void showVolume(){? ? ? ? System.out.println(r*r*3.14*h);? ? }? public static void main(String []args){? ? Cylinder ?cylinder=new ?Cylinder();//編譯顯示以下兩句有錯,去掉后最后的結果多了一個。 ? ? ? ? Cylinder b1=new Cylinder(); ? ? ? ? b1.getVolume();? ? ? ??? ? ? ? Cylinder b2=new Cylinder(); ? ? ? ? b2.showVolume();? ? }}
添加回答
舉報
0/150
提交
取消