62,614
社区成员
发帖
与我相关
我的任务
分享
package demo;
public interface Trainee {
void study();
}
package demo;
import static java.lang.System.*;
public abstract class Person {
protected final String school = "Home College";
static String domitory = "2B13";
public void eat() {
out.println("Eats shit.");
}
public void sleep() {
out.println("Sleeps like a pig!");
}
public void writeInfo() {
out.println(school);
writeAge();
writeHeight();
}
protected abstract void writeAge();
protected abstract void writeHeight();
}
package demo;
import static java.lang.System.*;
public class Student extends Person implements Trainee {
private int age;
private int height;
private String course = "College Engligh One";
public Student() {
age = 21;
height = 159;
}
public Student(int age, int height) {
this.age = age;
this.height = height;
}
@Override
public void study() {
out.println("Studies " + course);
}
public static void main(String[] args) {
out.println(Person.domitory);
Trainee studentA = new Student();
studentA.study();
Person studentB = new Student();
studentB.eat();
studentB.sleep();
Student studentC = new Student(22, 165);
studentC.writeInfo();
studentB.sleep();
}
@Override
protected void writeAge() {
out.println("My age is " + age);
}
@Override
protected void writeHeight() {
out.println("My height is " + height);
}
}