跪求大神解答一个java题目!!!! 10
跪求大神解答一个java题目!!!!定义一个Person抽象类,该类有姓名,年龄2个属性,有一个带有返回值的Stringtalk()抽象方法及带参构造方法和不带参数的构造...
跪求大神解答一个java题目!!!!定义一个Person抽象类,该类有姓名,年龄2个属性,有一个带有返回值的String talk()抽象方法及带参构造方法和不带参数的构造方法,定一个Worker(工人)类,该类继承Person类,新增薪水属性,并实现抽象方法,并且有一个带参构造函数调用抽象类的构造函数。
编写测试类测试Worker类,
备注:talk()方法用于自我介绍,
备注:属性名 薪水pay 展开
编写测试类测试Worker类,
备注:talk()方法用于自我介绍,
备注:属性名 薪水pay 展开
2个回答
展开全部
public abstract class Person {
private String name;
private Integer age;
public Person(){}
public Person(String name,Integer age){
this.name = name;
this.age = age;
}
public abstract String talk();
}
public class Worker extends Person{
private String pay;
public void setPay(String pay) {
this.pay = pay;
}
@Override
public String talk() {
return "I am a worker! + my sal is" + pay;
}
}
private String name;
private Integer age;
public Person(){}
public Person(String name,Integer age){
this.name = name;
this.age = age;
}
public abstract String talk();
}
public class Worker extends Person{
private String pay;
public void setPay(String pay) {
this.pay = pay;
}
@Override
public String talk() {
return "I am a worker! + my sal is" + pay;
}
}
展开全部
Person抽象类
package com.platform.wayin.example.action;
public abstract class Person {
String age;
String name;
public Person(String age, String name) {
super();
this.age = age;
this.name = name;
}
public Person() {
}
public abstract String talk();
}
Worker 类
package com.platform.wayin.example.action;
public class Worker extends Person{
String pay;
public Worker(String age, String name, String pay) {
super(age, name);
this.pay = pay;
}
public String talk(){
return "我的名字是"+this.name+",今年"+this.age+"岁,工资是"+this.pay+"元";
}
}
测试类
package com.platform.wayin.example.action;
public class WorkerTest {
public static void main(String[] args) {
Worker worker=new Worker("小明","20","5000");
System.out.println(worker.talk());
}
}
package com.platform.wayin.example.action;
public abstract class Person {
String age;
String name;
public Person(String age, String name) {
super();
this.age = age;
this.name = name;
}
public Person() {
}
public abstract String talk();
}
Worker 类
package com.platform.wayin.example.action;
public class Worker extends Person{
String pay;
public Worker(String age, String name, String pay) {
super(age, name);
this.pay = pay;
}
public String talk(){
return "我的名字是"+this.name+",今年"+this.age+"岁,工资是"+this.pay+"元";
}
}
测试类
package com.platform.wayin.example.action;
public class WorkerTest {
public static void main(String[] args) {
Worker worker=new Worker("小明","20","5000");
System.out.println(worker.talk());
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |