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.明天继续写例题。
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步