(完整word版)[零基础学JAVA]JavaSE面向对象部分-19.面向对象高级(07) 下载本文

内容发布更新时间 : 2024/12/26 2:23:25星期一 下面是文章的全部内容请认真阅读。

上季内容回顾: 代理设计、适配器设计 抽象类和接口的区别 本季主要知识点:

本季以题目讲解为主,详细的讲解了抽象类和接口的实际应用及典型的实例分析。 练习题一

abstract class Employee {

private String name; private int age; private String sex; public Employee(){}

public Employee(String name,int age,String sex) {

this.setName(name); this.setAge(age); this.setSex(sex); }

public void setName(String name) {

this.name = name; }

public void setAge(int age) {

this.age = age; }

public void setSex(String sex) {

this.sex = sex;

}

public String getName() {

return this.name; }

public int getAge() {

return this.age; }

public String getSex() {

return this.sex; }

//显示数据

public abstract String getInfo(); }

class Manager extends Employee {

//职务

private String job; //年薪

private float income; public Manager(){}

public Manager(String name,int age,String sex,String job,float income) {

super(name,age,sex); this.setJob(job);

this.setIncome(income); }

public void setJob(String job) {

this.job = job; }

public void setIncome(float income) {

this.income = income; }

public String getJob() {

return this.job; }

public float getIncome() {

return this.income; }

public String getInfo() {

return \管理层信息:\+\

+\姓名: \+super.getName()+\ +\年龄: \+super.getAge()+\ +\性别: \+super.getSex()+\ +\职务: \+this.getJob()+\ +\年薪: \+this.getIncome(); } }

class Worker extends Employee {

private String dept; private float salary; public Worker(){}

public Worker(String name,int age,String sex,String dept,float salary) {

super(name,age,sex); this.setDept(dept); this.setSalary(salary); }

public void setDept(String dept) {

this.dept = dept; }

public void setSalary(float salary) {

this.salary = salary; }

public String getDept() {

return this.dept; }

public float getSalary() {

return this.salary; }

public String getInfo() {

return \职员信息:\+\

+\姓名: \+super.getName()+\