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