继承+代码复用使用方法说人话

子类泛化父类 : 使用父类的方法

方法泛化方法: 使用已有的方法 在已有的方法上进行扩展;这就是多态的用途之一;

1. 输出基本信息的扩展

自己的方法只输出 基本信息

java 复制代码
public void printMethod()
    {
        System.out.println("学号: " + this.studentId);
        System.out.println("姓名: " + this.name);
        System.out.println("年龄: " + this.age);
    }

在只输出基本信息基础 添加上学生文件信息

java 复制代码
public void printMethodFile()
    {

        printMethod();
        System.out.print("学生文件" + this.studentFile);
    }

2.构造只设置基本信息 扩展

基本信息扩展:

java 复制代码
public Student(String studentId,String name, Integer age)
    {
        this.age = age;
        this.studentId = studentId;
        this.name = name;
    }
java 复制代码
public StudentIN(String studentId,String name, Integer age,String studentFile)
  {
       super(studentId,name,age);
       this.studentFile = studentFile;
   }
相关推荐
Highcharts.js3 小时前
倒置百分比堆叠面积图表示列详解|Highcharts大气成分图表代码
开发语言·信息可视化·highcharts·图表开发·面积图·图表示例·推叠图
csdn_aspnet4 小时前
C语言 Lomuto分区算法(Lomuto Partition Algorithm)
c语言·开发语言·算法
Dicky-_-zhang4 小时前
消息队列Kafka/RocketMQ选型与高可用架构:从单体到100万TPS的演进
java·jvm
晨曦中的暮雨4 小时前
4.15腾讯 CSIG云服务产线 一面
java·开发语言
存在morning4 小时前
【GO语言开发实践】二 GO 并发快速上手
大数据·开发语言·golang
fake_ss1984 小时前
AI时代学习全栈项目开发的新范式
java·人工智能·学习·架构·个人开发·学习方法
茉莉玫瑰花茶4 小时前
工作流的常见模式 [ 1 ]
java·服务器·前端
未若君雅裁4 小时前
Spring AOP、日志切面与声明式事务原理
java·后端·spring
No8g攻城狮5 小时前
【人大金仓】wsl2+ubuntu22.04安装人大金仓数据库V9
java·数据库·spring boot·非关系型数据库
xiaoerbuyu12335 小时前
开源Java 邮箱 基于SpringBoot+Vue前后端分离的电子邮件
java·开发语言