/* 編寫一個圓柱體類Cylinder,擁有:?@兩個成員變量? double h(私有,浮點(diǎn)); ?//圓柱體的高;? double r(私有,浮點(diǎn)); ?//圓柱體的半徑;??@構(gòu)造方法? Cylider(double r,double h) //創(chuàng)建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();//編譯顯示以下兩句有錯,去掉后最后的結(jié)果多了一個。 ? ? ? ? Cylinder b1=new Cylinder(); ? ? ? ? b1.getVolume();? ? ? ??? ? ? ? Cylinder b2=new Cylinder(); ? ? ? ? b2.showVolume();? ? }}
3 回答

產(chǎn)品經(jīng)理不是經(jīng)理
TA貢獻(xiàn)481條經(jīng)驗 獲得超143個贊
? Cylinder b1=new Cylinder();
?Cylinder b2=new Cylinder();
這兩句話各打印了一次結(jié)果
添加回答
舉報
0/150
提交
取消