~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
开发工具与关键技术:IDEA; JAVASE,Overload
撰写时间:2020-08-28
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
方法重载:实际上是完全不同的方法,只是名字相同而已(为什么要用方法重载:有很多功能上其实是相同的,而只是参数不同而已,但是一般方法名都是见名知义,但是却要用到两个方法,节省词汇等等一些原因吧。)
下面是构成重载的条件:1、在同一个类中、方法名相同,2、形参类型、形参个数、形参顺序不同
形参个数不同
public class demo {
//一个参数
public static void number(int numOne){
}
//两个参数
public static void number(int num,int numTwe){
}
//三个参数
public static void number(int num,int numTwe,int numThree){
}
}
形参类型不同
public class demo {
public static void type(int typeOne,double typeTwo){
}
public static void type(int typeOne,float typeTwo){
}
public static void type(long typeOne,float typeTwo){
}
}
形参顺序不同
public class demo {
public static void order(int orderOne,float orderTwo, double orderThree){
}
public static void order(float orderTwo, int orderOne, double orderThree){
}
public static void order(double orderThree,int orderOne,float orderTwo){
}
}