package case3;
public class superTest {
public static void main(String[] args) {
// 实例化一个Student类的对象s,为Student对象s中的school赋值,打印输出信息
/********* begin *********/
Student s = new Student("张三",18, "哈佛大学");
System.out.println("姓名:"+s.name+",年龄:"+s.age+",学校:"+s.school);
/********* end *********/
}
}
class Person {
/********* begin *********/
String name;
int age;
Person(String name, int age)
{
this.name = name;
this.age = age;
}
/********* end *********/
}
class Student extends Person {
/********* begin *********/
String school;
Student(String name,int age,String school)
{
super(name,age);
this.school = school;
}
/********* end *********/
}
Educoder -Java面向对象- 封装、继承和多态(第3关:super关键字的使用)
最新推荐文章于 2023-03-08 23:44:22 发布