public void setpersonVar(String name,int age,String sex){
personName = name;
personAge = age;
personSex = sex;
}
public void setpersonVar(String name,int age,String sex,String work,String phone){
personName = name;
personAge = age;
personSex = sex;
workPlace = work;
phoneNum =phone;
}这两个方法就是重载啊
personName = name;
personAge = age;
personSex = sex;
}
public void setpersonVar(String name,int age,String sex,String work,String phone){
personName = name;
personAge = age;
personSex = sex;
workPlace = work;
phoneNum =phone;
}这两个方法就是重载啊
解决方案 »
- 关于StringIndexOutOfBoundsException
- 1和2两个代码有区别么
- 在java中如何获取在画布加载的图像上用鼠标点击的字符(图像上有很多字符)
- 线程不能唤醒了....请帮我看看...
- Struts2 重定向以后,再次请求没有了
- 做了一个Frame,左边用来显示树,右边用来显示图片,可树死活都不出来,请各位大侠帮忙啊------在线等,急急急
- 小弟刚学java socket,请教个关于发送list的问题
- 6个人过河问题的算法讨论
- 求教execute方法的用法
- Cappuccino : Memory Leak & SoftReference
- javac -encoding 对class的编码有没有影响??
- java的问题,帮解释一下.
public void setpersonVar(String name,int age,String sex);
public void setpersonVar(String name,int age,String sex,String work,String phone);
这三个方法就构成了重载,重载就是名字一样,参数不一样,或顺序不一样。
是重载方法,
重载方法:方法名和返回值类型必须相同,参数列表必须不同(参数的个数不同 参数的类型不同,二者有一即可)
public void setpersonVar(String name,int age,String sex){
public void setpersonVar(String name,int age,String sex,String work,String phone){
很明显的重载啊
Overloading on return valuesIt is common to wonder “Why only class names and method argument lists? Why not distinguish between methods based on their return values?” For example, these two methods, which have the same name and arguments, are easily distinguished from each other: Feedback
void f() {}
int f() {}This works fine when the compiler can unequivocally determine the meaning from the context, as in int x = f( ). However, you can also call a method and ignore the return value. This is often referred to as calling a method for its side effect, since you don’t care about the return value, but instead want the other effects of the method call. So if you call the method this way: Feedback
f();how can Java determine which f( ) should be called? And how could someone reading the code see it? Because of this sort of problem, you cannot use return value types to distinguish overloaded methods.