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 + "读书");
}
}