抽象类继承问题 小白提问


package com.HelloWorld;


//雇员公有特性

abstract class Employee{

private String name;

private String id;

private double pay;

Employee(String name, String id, double pay){

this.name = name;

this.id = id;

this.pay = pay;

}

abstract public void work();

}

//程序员

class Programmer extends Employee{

Programmer(String name, String id, double pay){

super(name, id, pay);

}

public void work(){

System.out.println("敲代码....");

}

/*public String toString (){

return ;

}*/

}

//经理

class Manager extends Employee{

private int bonus;

Manager(String name, String id, double pay, int bonus){

super(name,id,pay);

this.bonus = bonus;

}

public void work(){

System.out.println("管理...");

}

/*public String toString(){

return ;

}*/

}

public class AbstractTest {


/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

Employee p = new Programmer("xiaoming", "xiaoming123", 100);

Employee m = new Manager("xiaohu", "xiaohu456",123, 12);

p.work();

m.work();

System.out.println(p);

System.out.println(m);


}


}

请问为了将我填入的属性输出,输出语句中该怎么写?

慕斯卡0247622
浏览 1162回答 2
2回答

ziom

重写toString(),在toString()中返回你当前类的属性拼接字符串
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java