Java Programming Chapter 4——The difference between overloading and overwriting.

The difference between overloading and overwriting.

If a method program with the same method name and return value type as the parent class but different parameter list is queued in the subclass, it will be compiled. At this time, there are two eat methods in the subclass, public void eat(int a){// The two methods that inherit from the parent class are no longer method overrides, but method overloads, so at runtime, which method to call is decided according to the actual parameters.

The result of running the program is

-eat()-

-sleep()-

相关推荐
乐观勇敢坚强的老彭4 分钟前
C++ 竞赛常用算法模板速查表
开发语言·c++·算法
0x537 分钟前
Java网络编程(四)
java·网络
离陌在学C#18 分钟前
C# 泛型:从基础到高级应用
开发语言·c#
ly768918 分钟前
Java 设计模式详解:从原则到 23 种经典模式
java·开发语言·设计模式
SomeB1oody21 分钟前
【RustyML入门】2.13. 孤立森林
开发语言·后端·机器学习·rust·教程
萧瑟余晖35 分钟前
Java深入解析篇三十之Java日志框架
java·开发语言
Herbert_hwt1 小时前
【C语言基础】常量、选择结构与运算符全解析
c语言·开发语言·算法
AI视觉网奇1 小时前
动作识别 视频理解大模型
开发语言·python·音视频
Suxing91 小时前
C语言基础分享:从“租房”到“拆迁”,C语言动态内存管理
java·数据结构·算法
减瓦1 小时前
别让 Java 版本选择变成生产事故
java