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

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

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

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;
   }
相关推荐
圆山猫6 小时前
[Virtualization](四):Linux KVM/RISC-V 的 vCPU 运行路径
java·linux·risc-v
微学AI7 小时前
一根针指向所有方向:挂谷猜想对 LLM Agent 技能-记忆架构的启示
开发语言·人工智能·架构·挂谷猜想
城管不管7 小时前
ReAct、Plan-and-Execute、Reflection 三大智能 Agent 范式核心区别
java·人工智能·算法·spring·ai·动态规划
IT小白杨7 小时前
从环境制备到自动化工作流:多账号运营的工程化架构拆解
java·经验分享·自动化·安全架构·指纹浏览器
豆瓣鸡7 小时前
算法日记 - Day3
java·开发语言·算法
萧瑟余晖8 小时前
Java深入解析篇九之NIO详解
java·网络·nio
韭菜炒鸡肝天8 小时前
VTK开发笔记(一):VTK介绍,Qt..+VSx+VTK.编译
开发语言·笔记·qt
The Chosen One9858 小时前
高进度算法模板速记(待完善)
java·前端·算法
Aaron - Wistron9 小时前
Web API C# (Furion版)带 单元测试
开发语言·后端·c#
Dxy123931021610 小时前
Python项目打包成EXE完整教程(PyInstaller实战避坑)
开发语言·python