当前位置:网站首页>jvm: 方法重载时,具体调用哪个方法,是由传入参数的静态类型来决定的,而不是由参数的实际类型来决定
jvm: 方法重载时,具体调用哪个方法,是由传入参数的静态类型来决定的,而不是由参数的实际类型来决定
2022-06-23 03:58:00 【amadeus_liu2】
一、示例
package com.example.controller;
public class TestOverload {
public static void main(String[] args) {
Grandpa grandpa=new Grandpa();
Grandpa father=new Father();
Grandpa offspring=new Offspring();
print(grandpa);
print(father);
print(offspring);
}
public static void print(Grandpa grandpa){
System.out.println("print grandpa......");
}
public static void print(Father father){
System.out.println("print father......");
}
public static void print(Offspring offspring){
System.out.println("print offspring......");
}
}
class Grandpa{
}
class Father extends Grandpa {
}
class Offspring extends Father{
}
二、运行输出:
三、分析:
grandpa、father、offspring这3个对象的静态类型都是Grandpa,它们的实际类型分别是Grandpa、Father、Offspring,
将这3个对象传递给print方法时,因为它们的静态类型为Grandpa,所以都会调用
public static void print(Grandpa grandpa){
System.out.println("print grandpa......");
}
边栏推荐
- B-string value (string DP) of the 16th Northeast College Students' Programming Competition (warm-up)
- STM32 clock tree misconfiguration causes boot to enter hard interrupt
- Jsonfield annotation in fastjson
- Design and implementation of spark offline development framework
- IP6809三线圈15W无线充电发射端方案ic英集芯
- 云原生大趋势下的容器化技术现状与发展
- STM32cube 串口使用DMA+IDLE接收不定长数据
- Introduction to MySQL (I) grammar
- MCS:连续随机变量——Chi-Square分布
- MCS:连续随机变量——LogNormal分布
猜你喜欢

Win11不能录制音频怎么办?Win11无法录入声音的解决方法

How much disk IO will actually occur for a byte of the read file?

Mathematical analysis_ Notes_ Chapter 1: set and mapping

The road of architects starts from "storage selection"

数学分析_笔记_第1章:集合与映射

Redis缓存穿透解决方案-布隆过滤器

Mysql入门学习(一)之语法

JDBC introductory learning (II) encapsulation tool class

英文字母pc是什么意思,互联网的pc指的是什么

Win software - (net framework) processed the certificate chain but terminated in a root certificate that is not trusted by the trusted provider
随机推荐
H5 适配全面屏
关于信息泄露和防御
How much disk IO will actually occur for a byte of the read file?
JVM原理之完整的一次GC流程
APP自动化测试-Appium进阶
Pkav simple blasting
GO语言-包的使用
云原生大趋势下的容器化技术现状与发展
STM32cube 串口使用DMA+IDLE接收不定长数据
第九章 APP项目测试(1)
Leetcode 797: all possible paths
2022年中国重卡智能化升级专题研究
hash---------history
Three implementation methods: left fixed and right adaptive (Flex, float + BFC, float margin left)
About information disclosure and defense
MCS: continuous random variable - student's t distribution
数据库连接异常:create connection error, url: jdbc:mysql://ip/数据库名, errorCode 0, state 08S01问题处理
软件设计开发笔记2:基于QT设计串口调试工具
MCS: discrete random variable Bernoulli distribution
Redis缓存穿透解决方案-布隆过滤器