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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
class S45 { int quan; String taste, temp; S45() { this(1); SOP("AAA"); } S45(int a) { this(1, ""); SOP("BBB"); } S45(int a, String b) { SOP("CCC"); } public void buyjuice() { SOP("要買什麼果汁:"); } public void buyjuice(String taste) { SOP(String.format("1杯%s汁", taste)); } public void buyjuice(int quan, String taste) { SOP(String.format("%d杯%s汁", quan, taste)); } public void buyjuice(String temp, String taste) { SOP(String.format("1杯%s的%s汁", temp, taste)); } public void buyjuice(int quan, String temp, String taste) { SOP(String.format("%d杯%s的%s汁", quan, temp, taste)); } private void SOP(String str) { System.out.println(str); } } public class Java_107_03_14_HW1 { public static void main(String[] args) { // TODO 自動產生的方法 Stub S45 s45 = new S45(); s45.buyjuice(); s45.buyjuice("蘋果"); s45.buyjuice(2, "蘋果"); s45.buyjuice("冰", "蘋果"); s45.buyjuice(3, "冰的", "蘋果"); } } |