Object-oriented assignment:
New a Person class, defined as an abstract class, contains the name: the name, age: the age, sex, sex, telephone: tel, occupation: pro properties, eat eat (), sleep the sleep () method -- a new Student class Student inherit the Person class, in addition to add professional major, class the className attribute, as well as learning study () method;
Override the toString method, the output of information of students;
New - the Teacher class inherit the Person class, in addition to add called the () method, and realize the curriculum Course interface;
Course interface: create access Course name, the method of the incoming Course parameters, output courses
CodePudding user response:
Person. Javapublic abstract class Person {
private String name;
private int age;
private String sex;
Private String tel;
Private String pro;
Public void eat () {
System. The out. Println (" eat ");
}
Public void sleep () {
System. The out. Println (" sleep ");
}
Public String getName () {
return name;
}
Public void elegantly-named setName (String name) {
this.name=name;
}
Public int getAge () {
Return the age;
}
Public void setAge (int age) {
this.age=age;
}
Public String getSex () {
Return sex;
}
Public void setSex (String sex) {
This. Sex=sex;
}
Public String getTel () {
Return tel;
}
Public void setTel (String tel) {
This. Tel=tel;
}
Public String getPro () {
Return pro;
}
Public void setPro (String pro) {
This. Pro=pro;
}
@ Override
Public String toString () {
Return "Person {+"
"Name='" + name +' \ '+'
"Age=" + age +
='" + ", sex sex +' \ ' '+
", tel='" + tel +' \ ' '+
", pro='" + pro +' \ ' '+
'} ';
}
}
Student. Java
public class Student extends the Person {
Private String major;
Private String className.
Public void study () {
System. The out. Println (" study ");
}
Public String getMajor () {
The return of major;
}
Public void setMajor (String) major {
This. Major=major;
}
Public String getClassName () {
Return the className.
}
Public void setClassName (String className) {
Enclosing the className=className.
}
@ Override
Public String toString () {
Return "Student {+"
"Major='" + major +' \ '+'
", the className='" + className +' \ ' '+
"} "+ super. ToString ();
}
}
The Teacher. Java
public class the Teacher extends the Person implements Course {
Private String subject;
Public void called the () {
System. The out. Println (" called ");
}
@ Override
Public String getSubjectName (String name) {
Return this. The subject;
}
}
Course. Java
public interface Course {
String getSubjectName (String name);
}