java复习笔记
Posted -YIN
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java复习笔记相关的知识,希望对你有一定的参考价值。
public class TestPerson {
public static void main(String[] args) {
Person person=new Person("李明","临潼",1234,"1234567@qq.com");
System.out.println(person.toString());
Person student=new Student("李华","西安",123,"12345@qq.com",100);
System.out.println(student.toString());
MyDate mydate=new MyDate(2001,05,29);
Person employee=new Employee("李莉","西安",12323,"1231@qq.com",3200,"教室",mydate.toString());
System.out.println(employee.toString());
Employee faculty=new Faculty("李莉","西安",12323,"1231@qq.com",3200,"教室",mydate.toString(),"早8晚6","讲师");
System.out.println(faculty.toString());
Employee staff=new Staff("李莉","西安",12323,"1231@qq.com",3200,"教室",mydate.toString(),"讲师");
System.out.println(staff.toString());
}
}
class Person{
private String name;
private String address;
private int tell;
private String Email;
public Person(){
}
public Person(String name,String address,int tell,String Email){
this.name=name;
this.address=address;
this.tell=tell;
this.Email=Email;
}
public String getName(){
return name;
}
public void setName(String name){
this.name=name;
}
public String getAddress(){
return address;
}
public void setAddress(String address){
this.address=address;
}
public int getTell(){
return tell;
}
public void setTell(int tell){
this.tell=tell;
}
public String getEmail(){
return Email;
}
public void setEmail(String Email){
this.Email=Email;
}
public String toString(){
return "Person 姓名:"+ name;
}
}
class Student extends Person{
private final int one=1;
private final int two=2;
private final int three=3;
private final int four=4;
private int grade;
public Student(){
}
public Student(String name,String address,int tell,String Email,int grade){
super(name,address,tell,Email);
this.grade=grade;
}
public int getGrade(){
return grade;
}
public void setGrade(int grade){
this.grade=grade;
}
@Override
public String toString(){
return "student 姓名:"+this.getName();
}
}
class Employee extends Person {
private double salary;
private String office;
private String hiredTime;
public Employee(){
}
public Employee(String name,String address,int tell,String Email,double salary,String office,String hiredTime){
super(name,address,tell,Email);
this.salary=salary;
this.office=office;
this.hiredTime=hiredTime;
}
public void setSalary(double salary){
this.salary=salary;
}
public double getSalary(){
return salary;
}
public void setOffice(String office){
this.office=office;
}
public String getOffice(){
return office;
}
public void setHiredTime(String hiredTime){
this.hiredTime=hiredTime;
}
public String getHiredTime(){
return hiredTime;
}
@Override
public String toString(){
return "employee 姓名:"+this.getName();
}
}
class Faculty extends Employee{
private String workTime;
private String rank;
public Faculty(){
}
public Faculty(String name,String address,int tell,String Email,double salary,String office,String hiredTime,String workTime,String rank){
super(name,address,tell,Email,salary,office,hiredTime);
this.workTime=workTime;
this.rank=rank;
}
public String getWorkTime(){
return workTime;
}
public void setWorkTime(String workTime){
this.workTime=workTime;
}
public String getRank(){
return rank;
}
public void setRank(String rank){
this.rank=rank;
}
@Override
public String toString(){
return "faculty 姓名:"+this.getName();
}
}
class Staff extends Employee {
private String title;
public Staff(){
}
public Staff(String name,String address,int tell,String Email,double salary,String office,String hiredTime,String title){
super(name,address,tell,Email,salary,office,hiredTime);
this.title = title;
}
public String getTitle(){
return title;
}
public void setTitle(String title){
this.title=title;
}
@Override
public String toString(){
return "staff 姓名:"+this.getName();
}
}
class MyDate {
//私有数据域
private int year;
private int month;
private int day;
//构造函数
public MyDate(){
}
public MyDate(int year,int month,int day){
this.year = year;
this.month = month;
this.day = day;
}
//修改器与访问器
public void setYear(int year){
this.year = year;
}
public int getYear(){
return year;
}
public void setMonth(int month){
this.month = month;
}
public int getMonth(){
return month;
}
public void setDay(int day){
this.day = day;
}
public int getDay(){
return day;
}
//方法重写
@Override
public String toString(){
return year+"年"+month+"月"+day+"日";
}
}
以上是关于java复习笔记的主要内容,如果未能解决你的问题,请参考以下文章