我是Java的新学习者。我想了解在函数和函数重载中传递参数的概念。我在java网站上发现了几个例子,其中给出了下面的代码,我怀疑如果将null传递给nh(),那么在输出中显示“string”的方式。下面是代码JAVA中函数重载的困惑
public class CLI_APP
{
public static void main(String[] args)
{
jh(null);
}
public static void jh(String s)
{
System.out.print("String");
}
public static void jh(Object o)
{
System.out.print("Object");
}
}
在相同的代码,如果下面的行添加
public static void jh(Integer s)
{
System.out.print("Integer");
}
我的
的编译错误 “方法不明确”
WHY这发生了吗?
所以,如果从整数改变为int将它称之为字符串的方法???? – 2014-09-06 05:48:11
是的,它会。通过执行上面的例子来检查它。 – bharatpatel 2014-09-06 06:24:18