I. The order of the arguments is different
Packagecom.huawei.test.java04;/*** This is Description * *@authorWang Ming Fei * @date 2018/08/29*/ Public classOverload { Public Static voidPrint (String s,inti) {System.out.println ("String s =" +s+ "\nint i=" +i); } Public Static voidPrintinti,string s) {System.out.println ("Int i=" +i+ "\nstring s=" +s); } Public Static voidMain (string[] args) {print (5, "KKKK"); System.out.println ("------------------"); Print ("CCCC", 4); }}
Output Result:
/library/java/javavirtualmachines/jdk1.8.0_171.jdk/contents/home/bin/java "-javaagent:/applications/intellij Idea.app/contents/lib/idea_rt.jar=53899:/applications/intellij Idea.app/contents/bin "-Dfile.encoding=UTF-8- classpath/library/java/javavirtualmachines/jdk1.8.0_171.jdk/contents/home/jre/lib/charsets.jar:/library/java/ javavirtualmachines/jdk1.8.0_171.jdk/contents/home/jre/lib/deploy.jar:/library/java/javavirtualmachines/ jdk1.8.0_171.jdk/contents/home/jre/lib/ext/cldrdata.jar:/library/java/javavirtualmachines/jdk1.8.0_171.jdk/ contents/home/jre/lib/ext/dnsns.jar:/library/java/javavirtualmachines/jdk1.8.0_171.jdk/contents/home/jre/lib/ ext/jaccess.jar:/library/java/javavirtualmachines/jdk1.8.0_171.jdk/contents/home/jre/lib/ext/jfxrt.jar:/ library/java/javavirtualmachines/jdk1.8.0_171.jdk/contents/home/jre/lib/ext/localedata.jar:/library/java/ javavirtualmachines/jdk1.8.0_171.jdk/contents/home/jre/lib/ext/nashorn.jar:/library/java/javavirtualmachines/ Jdk1.8.0_171.jdk/contents/home/jre/lib/ext/sunec.jar:/library/java/javavirtualmachines/jdk1.8.0_171.jdk/contents/home/jre/lib/ext/sunjce_ provider.jar:/library/java/javavirtualmachines/jdk1.8.0_171.jdk/contents/home/jre/lib/ext/sunpkcs11.jar:/ library/java/javavirtualmachines/jdk1.8.0_171.jdk/contents/home/jre/lib/ext/zipfs.jar:/library/java/ javavirtualmachines/jdk1.8.0_171.jdk/contents/home/jre/lib/javaws.jar:/library/java/javavirtualmachines/ jdk1.8.0_171.jdk/contents/home/jre/lib/jce.jar:/library/java/javavirtualmachines/jdk1.8.0_171.jdk/contents/ home/jre/lib/jfr.jar:/library/java/javavirtualmachines/jdk1.8.0_171.jdk/contents/home/jre/lib/jfxswt.jar:/ library/java/javavirtualmachines/jdk1.8.0_171.jdk/contents/home/jre/lib/jsse.jar:/library/java/ javavirtualmachines/jdk1.8.0_171.jdk/contents/home/jre/lib/management-agent.jar:/library/java/ javavirtualmachines/jdk1.8.0_171.jdk/contents/home/jre/lib/plugin.jar:/library/java/javavirtualmachines/ Jdk1.8.0_171.jdk/contents/home/jre/lib/resources.jar:/library/java/javavirtualmachInes/jdk1.8.0_171.jdk/contents/home/jre/lib/rt.jar:/library/java/javavirtualmachines/jdk1.8.0_171.jdk/contents /home/lib/ant-javafx.jar:/library/java/javavirtualmachines/jdk1.8.0_171.jdk/contents/home/lib/dt.jar:/library/ java/javavirtualmachines/jdk1.8.0_171.jdk/contents/home/lib/javafx-mx.jar:/library/java/javavirtualmachines/ jdk1.8.0_171.jdk/contents/home/lib/jconsole.jar:/library/java/javavirtualmachines/jdk1.8.0_171.jdk/contents/ Home/lib/packager.jar:/library/java/javavirtualmachines/jdk1.8.0_171.jdk/contents/home/lib/sa-jdi.jar:/library /java/javavirtualmachines/jdk1.8.0_171.jdk/contents/home/lib/tools.jar:/users/yanliya/downloads/ Chinashop-master/java Foundation/java_base/target/Classes Com.huawei.test.java04.OverLoadintI=5String S=KKKK------------------String S=CCCCintI=4Process finished with exit code0
Second, the main type of overloading
Packagecom.huawei.test.java04;/*** This is Description * *@authorWang Ming Fei * @date 2018/08/29*/ Public classOverLoad1 {Static voidprt (String s) {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 ("Double argument:"); F1 (x); F2 ((float) x); F3 ((Long) x); F4 ((int) x); F5 (( Short) x); F6 ((byte) x); F7 ((Char) x); } Public Static voidMain (string[] args) {OverLoad1 P=NewOverLoad1 (); P.testdouble (); }}
Output Result:
/library/java/javavirtualmachines/jdk1.8.0_171.jdk/contents/home/bin/java "-javaagent:/applications/intellij Idea.app/contents/lib/idea_rt.jar=53986:/applications/intellij Idea.app/contents/bin "-Dfile.encoding=UTF-8- classpath/library/java/javavirtualmachines/jdk1.8.0_171.jdk/contents/home/jre/lib/charsets.jar:/library/java/ javavirtualmachines/jdk1.8.0_171.jdk/contents/home/jre/lib/deploy.jar:/library/java/javavirtualmachines/ jdk1.8.0_171.jdk/contents/home/jre/lib/ext/cldrdata.jar:/library/java/javavirtualmachines/jdk1.8.0_171.jdk/ contents/home/jre/lib/ext/dnsns.jar:/library/java/javavirtualmachines/jdk1.8.0_171.jdk/contents/home/jre/lib/ ext/jaccess.jar:/library/java/javavirtualmachines/jdk1.8.0_171.jdk/contents/home/jre/lib/ext/jfxrt.jar:/ library/java/javavirtualmachines/jdk1.8.0_171.jdk/contents/home/jre/lib/ext/localedata.jar:/library/java/ javavirtualmachines/jdk1.8.0_171.jdk/contents/home/jre/lib/ext/nashorn.jar:/library/java/javavirtualmachines/ Jdk1.8.0_171.jdk/contents/home/jre/lib/ext/sunec.jar:/library/java/javavirtualmachines/jdk1.8.0_171.jdk/contents/home/jre/lib/ext/sunjce_ provider.jar:/library/java/javavirtualmachines/jdk1.8.0_171.jdk/contents/home/jre/lib/ext/sunpkcs11.jar:/ library/java/javavirtualmachines/jdk1.8.0_171.jdk/contents/home/jre/lib/ext/zipfs.jar:/library/java/ javavirtualmachines/jdk1.8.0_171.jdk/contents/home/jre/lib/javaws.jar:/library/java/javavirtualmachines/ jdk1.8.0_171.jdk/contents/home/jre/lib/jce.jar:/library/java/javavirtualmachines/jdk1.8.0_171.jdk/contents/ home/jre/lib/jfr.jar:/library/java/javavirtualmachines/jdk1.8.0_171.jdk/contents/home/jre/lib/jfxswt.jar:/ library/java/javavirtualmachines/jdk1.8.0_171.jdk/contents/home/jre/lib/jsse.jar:/library/java/ javavirtualmachines/jdk1.8.0_171.jdk/contents/home/jre/lib/management-agent.jar:/library/java/ javavirtualmachines/jdk1.8.0_171.jdk/contents/home/jre/lib/plugin.jar:/library/java/javavirtualmachines/ Jdk1.8.0_171.jdk/contents/home/jre/lib/resources.jar:/library/java/javavirtualmachInes/jdk1.8.0_171.jdk/contents/home/jre/lib/rt.jar:/library/java/javavirtualmachines/jdk1.8.0_171.jdk/contents /home/lib/ant-javafx.jar:/library/java/javavirtualmachines/jdk1.8.0_171.jdk/contents/home/lib/dt.jar:/library/ java/javavirtualmachines/jdk1.8.0_171.jdk/contents/home/lib/javafx-mx.jar:/library/java/javavirtualmachines/ jdk1.8.0_171.jdk/contents/home/lib/jconsole.jar:/library/java/javavirtualmachines/jdk1.8.0_171.jdk/contents/ Home/lib/packager.jar:/library/java/javavirtualmachines/jdk1.8.0_171.jdk/contents/home/lib/sa-jdi.jar:/library /java/javavirtualmachines/jdk1.8.0_171.jdk/contents/home/lib/tools.jar:/users/yanliya/downloads/ Chinashop-master/java Foundation/java_base/target/Classes Com.huawei.test.java04.OverLoad1DoubleArgument:f1 (Double) F2 (float) F3 (Long) F4 (int) F5 ( Short) f6 (byte) F7 (Char) Process finished with exit code0
Three: cannot overload based on return value type
08_java basic knowledge-method overloading