package cn;
public interface People {
void complexion();
}
2)定義壹個抽象類Asian,裏面包含壹個抽象方法voidnation();
package cn;
public abstract class Asian {
public abstract void nation();
}
3)定義壹個類Chinese,繼承自Asian,並且實現父類的抽象方法;要求在nation方法中輸出
"China";
package cn;
public class Chinese extends Asian {
@Override
public void nation() {
System.out.print("china");
}
}
4)定壹個學生類Student,繼承自Chinese,並實現接口People,在方法complexion中,輸出:
“complexionisyellow”
5)學生類中包含兩個私有成員變量name和age,壹個構造方法Student(Stringname,intage),用來實現對兩私有成員的初始化,兩個方法getName()和getAge(),用來返回name和age的
值.
6)在學生類中定義main方法,在其中生成壹個Student的對象S,name為“張三”
,age為
20;並調用方法getName(),getAge,nation()和complexion(),輸出信息:"張三,20,
China,complexionisyellow"。
package cn;
public class Student extends Chinese implements People {
private String name;
private int age;
@Override
public void complexion() {
System.out.print("complexionisyellow");
}
public static void main(String[] args) {
Student student = new Student();
student.setName("張三");
student.setAge(20);
String name = student.getName();
int age = student.getAge();
System.out.print(name + "," + age + ",");
student.nation();
System.out.print(",");
student.complexion();
}
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;
}
}