package com.xin.inherit;
public class Person /*extends Object*/{
String name;
int height;
public void rest(){
System.out.println("休息");
}
public static void main(String[] args) {
Student s=new Student("张三",180,90);
System.out.println(s instanceof Person);
s.rest();
}
}
class Student extends Person{ //扩展,继承,Person是父类,Student是子类
int score;
public void study(){
System.out.println("学习"+this.name);
}
public void rest(){
System.out.println("回宿舍睡觉");//rest方法的重写
}
public Student(String name,int height,int score){ //天然拥有父类的属性
this.name=name;
this.height=height;
this.score=score;
}
}
class Employee extends Person{
public void rest(){
System.out.println("办公区休息");//rest方法的重写
}
}
class Teacher{
int teacherId;
Person person=new Person();
Teacher(int teacherId;String name,int height){
this.teacherId=teacherId;
this.person.name=name;
this.person.height=height;
}
}
老师,这两个为什么会错误?
