public class Flower {
int petalCount = 0;
String s = new String("null");
Flower(int petals) {
petalCount = petals;
System.out.println(
"Constructor w/ int arg only, petalCount= "
+ petalCount);
}
Flower(String ss) {
System.out.println(
"Constructor w/ String arg only, s=" + ss);
s = ss;
}
}
这几个“Flower”是怎么回事哦???谢谢了哈!!!函数的重载!!!!
int petalCount = 0;
String s = new String("null");
Flower(int petals) {
petalCount = petals;
System.out.println(
"Constructor w/ int arg only, petalCount= "
+ petalCount);
}
Flower(String ss) {
System.out.println(
"Constructor w/ String arg only, s=" + ss);
s = ss;
}
}
这几个“Flower”是怎么回事哦???谢谢了哈!!!函数的重载!!!!
用的时候 Flower a;
a.Flower(1); //可以是个数字
a.Flower("aaa"); //也可以是个字符串
JAVA中的重载有以下的作用:
1 体现JAVA中多态的特性。
2 可以有效的减少程序的冗余代码。java重载形成条件:
1 相同的方法名称
2 参数必须不同
3 返回值可能不同