继承、多态

复习

继承、多态_第1张图片
需求:
编写一个抽象类:职员Employee,其中定义showSalary(int s)抽象方法;编写Employee的子类,分别是销售员Sales和经理Manager,分别在子类中实现对父类抽象方法的重写,并编写测试类Test查看输出结果

package cn.employee.test;

public abstract class Employee {
	abstract void showSalary(int s);
}

package cn.employee.test;

public class Manager extends Employee {

	@Override
	void showSalary(int s) {
		System.out.println("Manager:" + s);

	}

}

package cn.employee.test;

public class Sales extends Employee {

	@Override
	void showSalary(int s) {
		System.out.println("Sales:" + s);
	}

}

package cn.employee.test;

public class Test2 {

	public static void main(String[] args) {
		Employee s = new Sales();
		Employee m = new Manager();
		s.showSalary(50000);
		m.showSalary(80000);
	}

}

效果图

继承、多态_第2张图片

你可能感兴趣的:(java,android,开发语言)