复制代码
- //:PrimitiveOverloading.java
- //Promotionofprimitivesandoverloading
- publicclassPrimitiveOverloading{
- //booleancantbeautomaticallyconverted
- staticvoidprt(Strings){
- System.out.println(s);
- }
- voidf1(charx){prt("f1(char)");}
- voidf1(bytex){prt("f1(byte)");}
- voidf1(shortx){prt("f1(short)");}
- voidf1(intx){prt("f1(int)");}
- voidf1(longx){prt("f1(long)");}
- voidf1(floatx){prt("f1(float)");}
- voidf1(doublex){prt("f1(double)");}
- voidf2(bytex){prt("f2(byte)");}
- voidf2(shortx){prt("f2(short)");}
- voidf2(intx){prt("f2(int)");}
- voidf2(longx){prt("f2(long)");}
- voidf2(floatx){prt("f2(float)");}
- voidf2(doublex){prt("f2(double)");}
- voidf3(shortx){prt("f3(short)");}
- voidf3(intx){prt("f3(int)");}
- voidf3(longx){prt("f3(long)");}
- voidf3(floatx){prt("f3(float)");}
- voidf3(doublex){prt("f3(double)");}
- voidf4(intx){prt("f4(int)");}
- voidf4(longx){prt("f4(long)");}
- voidf4(floatx){prt("f4(float)");}
- voidf4(doublex){prt("f4(double)");}
- voidf5(longx){prt("f5(long)");}
- voidf5(floatx){prt("f5(float)");}
- voidf5(doublex){prt("f5(double)");}
- voidf6(floatx){prt("f6(float)");}
- voidf6(doublex){prt("f6(double)");}
- voidf7(doublex){prt("f7(double)");}
- voidtestConstVal(){
- prt("Testingwith5");
- f1(5);f2(5);f3(5);f4(5);f5(5);f6(5);f7(5);
- }
- voidtestChar(){
- charx=x;
- prt("charargument:");
- f1(x);f2(x);f3(x);f4(x);f5(x);f6(x);f7(x);
- }
- voidtestByte(){
- bytex=0;
- prt("byteargument:");
- f1(x);f2(x);f3(x);f4(x);f5(x);f6(x);f7(x);
- }
- voidtestShort(){
- shortx=0;
- prt("shortargument:");
- f1(x);f2(x);f3(x);f4(x);f5(x);f6(x);f7(x);
- }
- voidtestInt(){
- intx=0;
- prt("intargument:");
- f1(x);f2(x);f3(x);f4(x);f5(x);f6(x);f7(x);
- }
- voidtestLong(){
- longx=0;
- prt("longargument:");
- f1(x);f2(x);f3(x);f4(x);f5(x);f6(x);f7(x);
- }
- voidtestFloat(){
- floatx=0;
- prt("floatargument:");
- f1(x);f2(x);f3(x);f4(x);f5(x);f6(x);f7(x);
- }
- voidtestDouble(){
- doublex=0;
- prt("doubleargument:");
- f1(x);f2(x);f3(x);f4(x);f5(x);f6(x);f7(x);
- }
- publicstaticvoidmain(String[]args){
- PrimitiveOverloadingp=
- newPrimitiveOverloading();
- p.testConstVal();
- p.testChar();
- p.testByte();
- p.testShort();
- p.testInt();
- p.testLong();
- p.testFloat();
- p.testDouble();
- }
- }///:~
复制代码
- //:Demotion.java
- //Demotionofprimitivesandoverloading
- publicclassDemotion{
- staticvoidprt(Strings){
- System.out.println(s);
- }
- voidf1(charx){prt("f1(char)");}
- voidf1(bytex){prt("f1(byte)");}
- voidf1(shortx){prt("f1(short)");}
- voidf1(intx){prt("f1(int)");}
- voidf1(longx){prt("f1(long)");}
- voidf1(floatx){prt("f1(float)");}
- voidf1(doublex){prt("f1(double)");}
- voidf2(charx){prt("f2(char)");}
- voidf2(bytex){prt("f2(byte)");}
- voidf2(shortx){prt("f2(short)");}
- voidf2(intx){prt("f2(int)");}
- voidf2(longx){prt("f2(long)");}
- voidf2(floatx){prt("f2(float)");}
- voidf3(charx){prt("f3(char)");}
- voidf3(bytex){prt("f3(byte)");}
- voidf3(shortx){prt("f3(short)");}
- voidf3(intx){prt("f3(int)");}
- voidf3(longx){prt("f3(long)");}
- voidf4(charx){prt("f4(char)");}
- voidf4(bytex){prt("f4(byte)");}
- voidf4(shortx){prt("f4(short)");}
- voidf4(intx){prt("f4(int)");}
- voidf5(charx){prt("f5(char)");}
- voidf5(bytex){prt("f5(byte)");}
- voidf5(shortx){prt("f5(short)");}
- voidf6(charx){prt("f6(char)");}
- voidf6(bytex){prt("f6(byte)");}
- voidf7(charx){prt("f7(char)");}
- voidtestDouble(){
- doublex=0;
- prt("doubleargument:");
- f1(x);f2((float)x);f3((long)x);f4((int)x);
- f5((short)x);f6((byte)x);f7((char)x);
- }
- publicstaticvoidmain(String[]args){
- Demotionp=newDemotion();
- p.testDouble();
- }
- }///:~
欢迎光临 仓酷云 (http://ckuyun.com/) | Powered by Discuz! X3.2 |