封装、继承和多态 3super关键字使用

package case3;


public class superTest {
        public static void main(String[] args) {
        // 实例化一个Student类的对象s,为Student对象s中的school赋值,打印输出信息
                Student s=new Student("张三",18);
                s.school="哈佛大学";
                s.say();
                }
        }

        class Person {
            String name;
            int age;
            Person(String name,int age){
                this.name=name;
                this.age=age;
            }
        }

        class Student extends Person {
            String school;
            Student(String name,int age){
                super(name,age);
            }
            void say(){
                System.out.println("姓名:"+name+",年龄:"+age+",学校:"+school);
            }
        }

上一篇:初学类_(1)


下一篇:二、drf简单使用