/*继承与抽象类*/
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);
}
}

  

最新文章

  1. RFID-RC522、FM1702SL、M1卡初探
  2. BZOJ 1584 DP
  3. How do you install mysql-connector-python (development version) through pip?
  4. 网站压力测试工具webbench
  5. nyoj 19擅长排列的小明 (DFS)
  6. Awesome Python
  7. [原创] IIS7下顶级域名301跳转到WWW域名
  8. JS中的控制函数调用:call(),apply()和bind()
  9. (转)PHP获取今天、昨天、明天的日期
  10. Spring3 MVC 拦截器拦截不到的问题
  11. Spring mail 邮件发送的简单实现
  12. js_8_dom标签
  13. mac上adb command not found
  14. 预先封装数据的思路.md
  15. OpenCV入门之获取验证码的单个字符(字符切割)
  16. java加载类的顺序
  17. maven搭建springmvc+mybatis项目
  18. Android 安全提示 笔记
  19. (zxing.net)解码
  20. “System.Runtime.InteropServices.COMException”类型的第一次机会异常在 System.Windows.Forms.dll 中发生

热门文章

  1. UiAutomator2.0 - Toast信息的验证
  2. 【原创精品】mac 彻底卸载趋势科技
  3. maven pom.xml 里scope的作用
  4. 经验分享:PDF怎么提取页面
  5. 题解 P5315 【头像上传】
  6. Python3学习十四
  7. querySelector() 选择器语法
  8. Nginx 静态页面POST 请求提示405 Not Allowed
  9. Deepin 自动挂载win NTFS磁盘
  10. JS数字转中文