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 |
/** * CDogKind */ class CDogKind { String Kind, Name; int age; void show() { System.out.println("寵物種類:" + Kind); } } /** * CDog */ class CDog extends CDogKind { CDog(String Kind, String Name, int age) { this.Kind = Kind; this.Name = Name; this.age = age; } void setAge(int age) { this.age = age; } void setName(String Name) { this.Name = Name; } void show() { super.show(); System.out.println("寵物名子:" + this.Name); System.out.println("寵物年齡:" + this.age); } } /** * Java_2018_04_18_HW * Author:Dragonyue */ public class Java_2018_04_18_HW { public static void main(String[] args) { CDog myDog = new CDog("柯基", "小昌弟弟", 3); myDog.show(); } } |