public class Person {
String name;
int age;
int id = 1001;
public Person(){
System.out.println("我無處不在!");
}
public Person(String name){
this.name = name;
}
public Person(String name,int age){
this(name);
this.age = age;
}
public void eat(){
System.out.println("人:喫飯");
}
public void walk(){
System.out.println("人:走路");
}
}
public class Student extends Person{
String major;
int id = 1002;
public Student(){
}
public Student(String major){
super();
this.major = major;
}
public Student(String name,int age,String major){
super(name,age);
this.major = major;
}
@Override
public void eat() {
System.out.println("學生:多喫有營養的食物");
}
public void study(){
System.out.println("學生:學習知識");
this.eat();
super.eat();
walk();
}
public void show(){
System.out.println("name = " + name + ", age = " + age);
System.out.println("id = " + this.id);
System.out.println("id = " + super.id);
}
}
public class StudyTest {
public static void main(String[] args) {
Student student = new Student();
student.eat();
student.study();
student.walk();
Person person = new Person();
person.eat();
person.walk();
Person person1 = new Student();
person1.walk();
person1.eat();
}
}