/* 編寫(xiě)一個(gè)圓柱體類Cylinder,擁有:?@兩個(gè)成員變量? double h(私有,浮點(diǎn)); ?//圓柱體的高;? double r(私有,浮點(diǎn)); ?//圓柱體的半徑;??@構(gòu)造方法? Cylider(double r,double h) //創(chuàng)建Circle對(duì)象時(shí)將半徑初始化為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();//編譯顯示以下兩句有錯(cuò),去掉后最后的結(jié)果多了一個(gè)。 ? ? ? ? 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)驗(yàn) 獲得超143個(gè)贊
你沒(méi)傳參數(shù)進(jìn)去?? b1.getVolume(???);

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