package p4;
abstract class Person {
String name;
String address;
int phone;
String email;
public Person(String n,String a,int p,String e){
name=n;
address=a;
phone=p;
email=e;
}
public String toString() {
return "name: "+name+" address: "+address+" phone: "+phone+" email: "+email;
}
}
class Student extends Person{
String grade;
final String grade1="Freshman";
final String grade2="Sophomore";
final String grade3="Junior";
final String grade4="Senior";
public Student(String n, String a, int p, String e,String g) {
super(n, a, p, e);
switch(g) {
case grade1:grade=grade1;break;
case grade2:grade=grade2;break;
case grade3:grade=grade3;break;
case grade4:grade=grade4;break;
}
}
public String toString() {
super.toString();
return " grade: "+grade;
}
}
class Employee extends Person{
String office;
double salary;
String hireTime;
public Employee(String n, String a, int p, String e,String o,double s,String h) {
super(n, a, p, e);
office=o;
salary=s;
hireTime=h;
}
public String toString() {
super.toString();
return " office:"+office+" salary: "+salary+" hireTime: "+hireTime;
}
}
class Faculty extends Employee{
String officeTime;
String grade;
public Faculty(String n, String a, int p, String e, String o, double s, String h,String oT,String g) {
super(n, a, p, e, o, s, h);
officeTime=oT;
grade=g;
}
public String toString() {
super.toString();
return " officeTime: "+officeTime+" grade: "+grade;
}
}
class Staff extends Employee{
String title;
public Staff(String n, String a, int p, String e, String o, double s, String h,String t) {
super(n, a, p, e, o, s, h);
title=t;
}
public String toString() {
super.toString();
return " title: "+title;
}
}
package p4;
import java.util.ArrayList;
public class text {
public static void main(String[] args) {
Student student=new Student("Jake","Ninth street 145",6532548,"1452874596@qq.com","Freshman");
Faculty faculty=new Faculty("Faker","First street 203",6538614,"996325481@qq.com","Fifth floor 513",13561.00,"2016/2/14","two years","Associate Professor");
Staff staff=new Staff("Faker","First street 203",6538614,"996325481@qq.com","Fifth floor 513",13561.00,"2016/2/14","Security");
ArrayList<Person>person=new ArrayList<Person>();
person.add(student);
person.add(faculty);
person.add(staff);
System.out.println(person);
}
}
toString() 这部分有问题。没有继承成功
我知道了!计入了,但是没有加到 return 里面