0
点赞
收藏
分享

微信扫一扫

SuperDemo


package com.shrimpking.t2;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : Shrimpking
 * @create 2024/9/16 20:50
 */
class Person5{
    String name;
    int age;

    public Person5(String name,int age){
        this.name = name;
        this.age = age;
    }
}

class Student5 extends Person5{

    String school;

    public Student5(String name, int age,String school)
    {
        //使用super调用父类的构造方法
        super(name, age);
        this.school = school;
    }
}

public class SuperDemo
{
    public static void main(String[] args)
    {
        Student5 stu = new Student5("Jack",30,"大学");
        System.out.printf("我是%s,今年%d岁,在%s读书",stu.name,stu.age,stu.school);

    }
}

举报

相关推荐

0 条评论