Java基礎:重載篇之基本類型的重載

  • 1、在重載過程中,如果傳入的實際參數類型小於方法中聲明的形式參數類型時,實際數據類型就會被提升,同理,如果傳入的實際參數大於方法中聲明的形式參數,那麼實際參數就會被降低
    char<byte<short<int<long<float<double
  • 2、char類型特殊,在提升/降低過程中,只會直接與int轉化

驗證代碼.

7:->f1(int):7 f2(int):7 f3(int):7 f4(int):7 f5(long):7 f6(float):7.0 f7(double):7.0 
Char:x->f1(char):x f2(int):120 f3(int):120 f4(int):120 f5(long):120 f6(float):120.0 f7(double):120.0 
Byte:0->f1(byte):0 f2(byte):0 f3(short):0 f4(int):0 f5(long):0 f6(float):0.0 f7(double):0.0 
Short:6->f1(short):6 f2(short):6 f3(short):6 f4(int):6 f5(long):6 f6(float):6.0 f7(double):6.0 
Int:0->f1(int):0 f2(int):0 f3(int):0 f4(int):0 f5(long):0 f6(float):0.0 f7(double):0.0 
Long:0->f1(long):0 f2(long):0 f3(long):0 f4(long):0 f5(long):0 f6(float):0.0 f7(double):0.0 
Float:0.0->f1(float):0.0 f2(float):0.0 f3(float):0.0 f4(float):0.0 f5(float):0.0 f6(float):0.0 f7(double):0.0 
Double:0.0->f1(double):0.0 f2(double):0.0 f3(double):0.0 f4(double):0.0 f5(double):0.0 f6(double):0.0 f7(double):0.0 
-------------------------
7:->fu1(double):7.0 fu2(float):7.0 fu3(long):7 fu4(int):7 fu5(int):7 fu6(int):7 fu7(int):7 
Char:x->fu1(double):120.0 fu2(float):120.0 fu3(long):120 fu4(int):120 fu5(int):120 fu6(int):120 fu7(char):x 
Byte:0->fu1(double):0.0 fu2(float):0.0 fu3(long):0 fu4(int):0 fu5(short):0 fu6(byte):0 fu7(byte):0 
Short:6->fu1(double):6.0 fu2(float):6.0 fu3(long):6 fu4(int):6 fu5(short):6 fu6(short):6 fu7(short):6 
Int:0->fu1(double):0.0 fu2(float):0.0 fu3(long):0 fu4(int):0 fu5(int):0 fu6(int):0 fu7(int):0 
Long:0->fu1(double):0.0 fu2(float):0.0 fu3(long):0 fu4(long):0 fu5(long):0 fu6(long):0 fu7(long):0 
Float:0.0->fu1(double):0.0 fu2(float):0.0 fu3(float):0.0 fu4(float):0.0 fu5(float):0.0 fu6(float):0.0 fu7(float):0.0 
Double:0.0->fu1(double):0.0 fu2(double):0.0 fu3(double):0.0 fu2(double):0.0 fu5(double):0.0 fu6(double):0.0 fu7(double):0.0 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章