一、子类的定义
package javastudy;
public class Student extends Person
{
int score;
//覆盖父类里面的函数,也叫函数的重写
void display()
{
System.out.println("your name"+","+"you height is "+ height+"你的成绩是:"+ score);
}
}
二、子类的调用
package javastudy;
public class TestIt
{
public static void main(String[] args)
{
//父类型
Person zhang=new Person();
zhang.name="zhang";
zhang.height=170;
zhang.display();
//定义新类型
Student s=new Student();
s.name="Mary";
s.height=180;
s.score=90;
s.display();
}
}