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

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

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

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;
   }
相关推荐
@国境以南,太阳以西2 小时前
从0实现OnCall基于Python语言框架
开发语言·python
qq5680180762 小时前
一个基于Spring Boot的简单网吧管理系统
java·spring boot·后端
前端小雪的博客.2 小时前
Java for 循环详解:从基础语法到实战案例(新手友好版)
java·java基础·for循环·循环结构
weixin_307779132 小时前
提升 LLM 输出鲁棒性:使用 json_repair 智能修复非标准 JSON
开发语言·人工智能·算法·json·软件工程
断手当码农2 小时前
Java算法题常见的20种输入模板(ACM / LeetCode 通用)
java
hashiqimiya2 小时前
spring报错
java·后端·spring
yaoxin5211232 小时前
352. Java IO API - Java 文件操作:java.io.File 与 java.nio.file 功能对比 - 4
java·python·nio
重庆兔巴哥2 小时前
如何使用Dev-C++的Windows API进行GUI开发?
开发语言·c++·windows
y = xⁿ2 小时前
【LeetCodehot100】T24:两两交换链表中的节点 T25:K个一组翻转链表
java·网络·数据结构·算法·链表