有关short与int的重载[jase基础]
生活随笔
收集整理的這篇文章主要介紹了
有关short与int的重载[jase基础]
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
public class Test{
void max(int a, int b){
System.out.println( a>b?a:b);
}
void max(short a,short b){
System.out.println( a>b?a:b);
}
public static void main(String[] args){
Test t = new Test();
t.max(3,4);
}
}
上面這個(gè)肯定是重載,問(wèn)題在于何時(shí)執(zhí)行max(short a,short b).
由于jvm在默認(rèn)情況下都會(huì)把整數(shù)轉(zhuǎn)化為int類(lèi)型。因此只會(huì)執(zhí)行max(int a,int b).
下面可以執(zhí)行到:
Test t = new Test();
short a = 3;
short b = 4;
t.max(a,b);
void max(int a, int b){
System.out.println( a>b?a:b);
}
void max(short a,short b){
System.out.println( a>b?a:b);
}
public static void main(String[] args){
Test t = new Test();
t.max(3,4);
}
}
上面這個(gè)肯定是重載,問(wèn)題在于何時(shí)執(zhí)行max(short a,short b).
由于jvm在默認(rèn)情況下都會(huì)把整數(shù)轉(zhuǎn)化為int類(lèi)型。因此只會(huì)執(zhí)行max(int a,int b).
下面可以執(zhí)行到:
Test t = new Test();
short a = 3;
short b = 4;
t.max(a,b);
轉(zhuǎn)載于:https://www.cnblogs.com/java0721/archive/2011/11/25/2602773.html
總結(jié)
以上是生活随笔為你收集整理的有关short与int的重载[jase基础]的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Access 报表打印之分组页码实现(轉
- 下一篇: 织梦DedeCMS播放本地视频文件插件