// class 子类 extentd 父类 {}
// 很多情况下: 会把子类称为派生类,把父类称为超类(superCall)
class Person {
private String name;
private int age;
public void setName(String name){
this.name = name;
}
public void setAge(int age){
this.age = age;
}
public String getName(){
return this.name;
}
public int getAge(){
return this.age;
}
}
class Student extends Person {
private String school;
public void setSchool(String school){
this.school = school;
}
public String getSchool(){
return this.school;
}
}
public class HelloWorld {
public static void main(String args[]){
Student stu = new Student();
stu.setName("李寻欢");// 子类可以直接调用父类中方法
stu.setAge(22);
stu.setSchool("清华大学");
System.out.println("姓名:" + stu.getName() + ",年龄:" + stu.getAge() + ",学校:" + stu.getSchool());
}
}
标签:school,8.2,String,继承,age,name,stu,public,定义
From: https://www.cnblogs.com/pansidong/p/17463285.html