1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | class CBox{ private int length; private int width; private int height; public CBox (int l , int w , int h){ length = l; width = w; height = h; } public CBox (){ this (6,10,8); System.out.println("沒有引數的建構元CBox長="+length+" 寬="+width+" 高="+height); } public void show (){ System.out.println("有引數的建構元CBox長="+length+" 寬="+width+" 高="+height); } } public class hw9_1{ public static void main(String args[]){ CBox box1 = new CBox(); CBox box2 = new CBox(6,10,8); box2.show(); } } |
Direct link: https://paste.plurk.com/show/UYkOuf6CKoXxXhuBP0Zm