调用重载方法

时间:2015-10-02 18:18:22

标签: string methods char int overflow

我似乎无法完成这项工作,更不用说编译而且我对如何修复它感到茫然。我的老师给了我们以下代码(为了问题而简化):

public static void doing1(String s) {
    // add code here
}

public static void doing2(char start, char end) {
    // add code here
}

public static int doing3(int num) {
    // add code here
}

public static void doing4(Scanner keyboard) {
    // add code here
}

我知道每种方法需要做什么(我的意思)我只是不知道如何在main方法中打印出来。我们无法更改提供给我们的代码,只能添加它。

谢谢!

1 个答案:

答案 0 :(得分:0)

重载方法意味着具有相同的方法名称,但方法签名(传入的参数)不同。所以,你所拥有的实际上不是一个重载,它是针对独特的方法,因为它们都有不同的名称。至于没有编译...你发布的内容看起来很好 - 也许你有一个错误高于或低于该代码。我相信这就是你要找的东西:

public static void doing(String s) {
    // add code here
}

public static void doing(char start, char end) {
    // add code here
}

public static int doing(int num) {
    // add code here
}

public static void doing(Scanner keyboard) {
    // add code here
}

这是来自全能的John Skeet的reference on overloads