java继承

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 里面

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值