public class Overloading {
static void printing() {
System.out.println("Something being printed here");
}
static void printing(String name) {
System.out.println("hello"+name);
}
public static void main(String[] args) {
printing();
printing(rizwana);
}
}
我正在尝试检查方法重载。但这是我得到的错误。
error: cannot find symbol
printing(rizwana);
symbol: variable rizwana
location: class Overloading
答案 0 :(得分:0)
rizwana
是指您未在代码中创建的变量。如果要传递字符串,则应将其作为"rizwana"
传递。
将方法称为:printing("rizwana");
答案 1 :(得分:0)
printing(String name)方法将接受一个字符串参数。所以你应该使用打印(" rizwana")而不是打印(rizwana)。你可以这个
class Overloading {
static void printing() {
System.out.println("Something being printed here");
}
static void printing(String name) {
System.out.println("hello "+name);
}
public static void main(String[] args) {
printing();
printing("rizwana");
}
}