求一个java编程题的答案

定义满足如下要求的类:
1)定义一个接口People,里面包含一个方法voidcomplexion();
2)定义一个抽象类Asian,里面包含一个抽象方法voidnation();
3)定义一个类Chinese,继承自Asian,并且实现父类的抽象方法;要求在nation方法中输出
"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"。

第1个回答  2019-06-22
1)定义一个接口People,里面包含一个方法voidcomplexion();
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;
}
}
第2个回答  2019-06-22

本回答被提问者采纳
相似回答