Java求解:其大家帮忙解决下面一道习题,谢谢了!
定义类Person及其子类Student、Employee,Employee的子类Manager,每个类定义下列成员变量:Person:姓名、年龄、家庭住址Student...
定义类Person及其子类Student、Employee,Employee的子类Manager,每个类定义下列成员变量:
Person:姓名、年龄、家庭住址
Student:学好、年级
Employee:工资、受聘日期
Manager:职务名称
每个类定义构造方法初始化所有变量,覆盖toString()方法输出所有成员变量值。创建这些类的对象,并调用toString()方法。 展开
Person:姓名、年龄、家庭住址
Student:学好、年级
Employee:工资、受聘日期
Manager:职务名称
每个类定义构造方法初始化所有变量,覆盖toString()方法输出所有成员变量值。创建这些类的对象,并调用toString()方法。 展开
1个回答
展开全部
class Person {
public String name="zhangsan";
public int age=18;
public String add="china";
public String toString() {
return name+","+age+","+add;
}
}
class Student extends Person{
public String no="001";
public String grade="1";
public String toString() {
return super.toString()+","+no+","+grade;
}
}
class Employee{
public double salary=1000;
public String date="2010-01-01";
public String toString() {
return salary+","+date;
}
}
class Manager extends Employee{
public String dutyName="boshi";
public String toString() {
return super.toString()+","+dutyName;
}
}
public class Test {
public static void main(String[] args) {
Person person=new Person();
Student student=new Student();
Employee employee=new Employee();
Manager manager=new Manager();
System.out.println(person);
System.out.println(student);
System.out.println(employee);
System.out.println(manager);
}
}
public String name="zhangsan";
public int age=18;
public String add="china";
public String toString() {
return name+","+age+","+add;
}
}
class Student extends Person{
public String no="001";
public String grade="1";
public String toString() {
return super.toString()+","+no+","+grade;
}
}
class Employee{
public double salary=1000;
public String date="2010-01-01";
public String toString() {
return salary+","+date;
}
}
class Manager extends Employee{
public String dutyName="boshi";
public String toString() {
return super.toString()+","+dutyName;
}
}
public class Test {
public static void main(String[] args) {
Person person=new Person();
Student student=new Student();
Employee employee=new Employee();
Manager manager=new Manager();
System.out.println(person);
System.out.println(student);
System.out.println(employee);
System.out.println(manager);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询