0
点赞
收藏
分享

微信扫一扫

SuperDemo2


package com.shrimpking.t2;

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

    //父类构造方法
    public Person6(){

    }

    public String talk(){
        return String.format("我是%s,今年%d岁",this.name,this.age);
    }
}

class Student6 extends Person6{
    String school;

    //子类构造的方法
    public Student6(String name,int age,String school){
        //使用super可以调用父类的属性
        super.name = name;
        super.age = age;
        //使用super可以调用父类的方法
        System.out.println(super.talk());
        this.school = school;
    }
}

public class SuperDemo2
{
    public static void main(String[] args)
    {
        Student6 stu = new Student6("Jack",30,"大学");
        System.out.println("我在" + stu.school + "读书");
    }
}

举报

相关推荐

单链表2-2

技术2---swagger2

2020/2/22-2

javase 2-2 类

2

*(p + 2)和*p+2

0 条评论