2020.8.26第五十一天
例 9.4对象数组
1 public class cjava { 2 public static void main(String[] args) { 3 Box a[]= {new Box(10,12,15),new Box(15,18,20),new Box(16,20,26)}; 4 System.out.println("The volume of a[0] is "+a[0].volume()); 5 System.out.println("The volume of a[1] is "+a[1].volume()); 6 System.out.println("The volume of a[2] is "+a[2].volume()); 7 } 8 } 9 class Box{ 10 int height; 11 int width; 12 int length; 13 Box(int h,int w,int len){ 14 height=h; 15 width=w; 16 length=len; 17 } 18 int volume() { 19 return (height*width*length); 20 } 21 }
2.遇到的问题:无
3.明天继续写例题
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步