抽象类可以被很多类继承,有没有可能这样一种情况,我在抽象类里面写一个带对象参数的抽象方法,如下代码所示,请问可以实现吗??可以实现的话,这个类参数该怎写呢?- class Demo6 {
- public static void main(String[] args) {
- Programmer p = new Programmer("asd","123",8000);
- p.work();
- Manager m =new Manager("zxc","456",20000,5000);
- m.work();
- }
- }
- abstract class Employee{
- private String name;
- private String id;
- private int pay;
- private int bonus;
- public abstract void work(类参数);
- Employee(){};
- Employee(String name,String id,int pay){
- this.name = name;
- this.id = id;
- this.pay = pay;
- };
- Employee(String name,String id,int pay,int bonus){
- this.name = name;
- this.id = id;
- this.pay = pay;
- this.bonus = bonus;
- };
- public String getName(){
- return name;
- }
- public String getId(){
- return id;
- }
- public int getPay(){
- return pay;
- }
- public int getBonus(){
- return bonus;
- }
-
- public void speak(){
- if(bonus == 0)
- System.out.println("我是"+name+",我的ID是"+id+"我的工资是:"+pay+",我没有奖金。");
- else
- System.out.println("我是"+name+",我的ID是"+id+"我的工资是:"+pay+"奖金是:"+bonus);
- }
-
- }
- class Programmer extends Employee{
- Programmer(){};
- Programmer(String name,String id, int pay){
- super(name,id,pay);
- };
- public void work(类参数){
- System.out.println("我是程序员,我的工作是编程!");
- 类.speak();
-
- }
- }
- class Manager extends Employee{
- Manager(){};
- Manager(String name,String id,int pay,int bonus){
- super(name,id,pay,bonus);
- };
- public void work(类参数){
- System.out.println("我是经理,我的工作是管理!");
- 类.speak();
- }
- }
复制代码 抽象类可以被很多类继承,有没有可能这样一种情况,我在抽象类里面写一个带对象参数的抽象方法,如下代码所示,请问可以实现吗??可以实现的话,这个类参数该怎写呢? |