Java作业十二(2017-11-13)
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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | /*继承与抽象类*/ package com.baidu.www; abstract class Person { private String name; private int age; public String getName() { return name; } public void setName(String name) { this .name = name; } public int getAge() { return age; } public void setAge( int age) { this .age = age; } public Person(String name, int age) { this .name = name; this .age = age; } public Person() { super (); } @Override public String toString() { return "Person [name=" + name + ", age=" + age + "]" ; } public abstract String speak(); } class ZiXia extends Person{ private float score; public ZiXia(String name, int age, float score) { super (name, age); this .setScore(score); } @Override public String speak() { return "紫霞信息:" + super .getName()+ " " + super .getAge()+ "岁 " + this .score+ "人气" ; } public float getScore() { return score; } public void setScore( float score) { this .score = score; } } class ZhiZunBao extends Person { private float salary; public ZhiZunBao(String name, int age, float salary) { super (name, age); this .setSalary(salary); } @Override public String speak() { return "至尊宝信息:" + super .getName()+ " " + super .getAge()+ "岁 " + this .salary+ "人气" ; } public float getSalary() { return salary; } public void setSalary( float salary) { this .salary = salary; } } public class GM { public static void main(String[] args) { Person ZiXia= new ZiXia( "仙子" , 19 , 10 ); Person ZhiZunBao= new ZhiZunBao( "人" , 18 , 10 ); print(ZiXia.speak()); print(ZhiZunBao.speak()); } private static void print(String speak) { System.out.println(speak); } } |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步