public class Person {//定义类
protected String name;
protected int age;
public void Say(){
System.out.println(name+"can say");
}
public void setName(String name){
this.name=name; //???
}
protected String name;
protected int age;
public void Say(){
System.out.println(name+"can say");
}
public void setName(String name){
this.name=name; //???
}
}
(新类)
public class Students extends Person {//继承
String schoolname;//增加属性
public void Gotoschool(){//增加方法
System.out.println("I an going to school");
}
public static void main(String args[]){
Students stu1=new Students();
stu1.name="mingm";stu1.age=10;//引用继承自父类的变量
stu1.schoolname="CQ";
stu1.Say();//调用继承自父类的方法
stu1.Gotoschool();//调用子类新增方法
System.out.println("my name is"+stu1.name);
System.out.println("My schoolname is"+stu1.schoolname);
}
}