方法重载 - 找不到符号

时间:2015-11-27 19:41:38

标签: find symbols overloading

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

2 个答案:

答案 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");
    }
}