2020.8.24第四十九天

例 9.2双构造函数

 1 public class cjava {
 2     public static void main(String[] args) {
 3         Box b1=new Box();
 4        System.out.println("The volume of box1 is "+b1.volume());
 5         Box b2=new Box(15,30,25);
 6        System.out.println("The volume of box2 is "+b2.volume());
 7 }
 8 }
 9 class Box{
10     int height;
11     int width;
12     int length;
13     Box(){
14         height=10;
15         width=10;
16         length=10;
17     }
18     Box(int h,int w,int len){
19         height=h;
20         width=w;
21         length=len;
22     }
23     int volume() {
24        return (height*width*length);
25     }
26 }

 2.遇到的问题:无

3.明天继续写例题。

原文地址:https://www.cnblogs.com/Nojava/p/13556386.html