当前位置:网站首页>Daily code series (10)

Daily code series (10)

2020-12-07 19:15:56 Li Jiayu

 1 class Cylinder {
 2   private double radius;
 3   private int height;
 4   private double pi=3.14;
 5   String color;
 6   public Cylinder() {
 7     this(2.5,5," Red ");
 8     System.out.println(" The parameterless constructor was called ");
 9   }
10   public Cylinder(double r,int h,String str) {
11     System.out.println(" Parameter constructor called ");
12     radius=r; height=h;color=str;
13   }
14   double area() {
15     return pi*radius*radius;
16   }
17   double volume() {
18     return area()*height;
19   }
20 }
21 public class C1_6 {
22   public static void main(String[] args) {
23     Cylinder volu=new Cylinder();
24     System.out.println(" The bottom area is : "+volu.area());
25     System.out.println(" The volume is : "+volu.volume());
26   }
27 }

 

版权声明
本文为[Li Jiayu]所创,转载请带上原文链接,感谢
https://chowdera.com/2020/12/20201207191509300x.html