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
| public class Example { public static void main(String[] args) { System.out.println("====人===="); Person person = new Person("叽里呱啦","默认皮肤"); person.say(); person.showSkin(); person.walk(); person.eat(); person.sleep();
System.out.println("====中国人===="); Person chinese = new Chinese("中文","黄皮肤"); chinese.say(); chinese.showSkin(); chinese.walk(); chinese.eat(); chinese.sleep(); System.out.println("====美国人===="); Person american = new American("英文","白皮肤"); american.say(); american.showSkin(); american.walk(); american.eat(); american.sleep(); } } class Person { String language; String skinColor; public Person() {} public Person(String language, String skinColor) { this.language = language; this.skinColor = skinColor; } public void say(){ System.out.println("说"+this.language); } public void showSkin(){ System.out.println(this.skinColor); } public void walk(){ System.out.println("人走路"); } public void eat(){ System.out.println("人吃饭"); } public void sleep(){ System.out.println("人睡觉"); } } class Chinese extends Person { public Chinese(){} public Chinese(String language, String skinColor) { super(language,skinColor); } } class American extends Person { public American(){} public American(String language, String skinColor) { super(language,skinColor); } }
|