在一個類的屬性為一個類(例如一個學生類的成績屬性為成績類,成績屬性是科目加分數)
阿新 • • 發佈:2019-02-04
public class Student {
private String name;
private int age;
private Grade grade;
private Grade grade2;
public Student() {
super();
}
public Student(String name, int age, Grade grade,Grade grade2) {
super();
this.name = name;
this.age = age;
this.grade = grade;
this.grade2 = grade2;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public Grade getGrade() {
return grade;
}
public void setGrade(Grade grade) {
this.grade = grade;
}
public Grade getGrade2() {
return grade2;
}
public void setGrade2(Grade grade2) {
this.grade2 = grade2;
}
@Override
public String toString() {
return "Student [name=" + name + ", age=" + age + ", " + grade + ", " + grade2 + "]";
}
}
private String name;
private int age;
private Grade grade;
private Grade grade2;
public Student() {
super();
}
public Student(String name, int age, Grade grade,Grade grade2) {
super();
this.name = name;
this.age = age;
this.grade = grade;
this.grade2 = grade2;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public Grade getGrade() {
return grade;
}
public void setGrade(Grade grade) {
this.grade = grade;
}
public Grade getGrade2() {
return grade2;
}
public void setGrade2(Grade grade2) {
this.grade2 = grade2;
}
@Override
public String toString() {
return "Student [name=" + name + ", age=" + age + ", " + grade + ", " + grade2 + "]";
}
}