这个程序做什么用的?

时间:2014-06-14 05:20:31

标签: java

面试官让我解释这段代码。它做了什么?

public class Test {
    public void methodOne(Object obj) {
        System.out.println("Object as Parameter");
    }

    public void methodOne(String str) {
        System.out.println("String as parameter");
    }

    public static void main(String[] args) {
        Test t = new Test();
        t.methodOne(new Object());
        t.methodOne("");
        t.methodOne(null);
    }
}

1 个答案:

答案 0 :(得分:0)

$ java -version
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

$ javac Test.java 
$ java Test
Object as Parameter
String as parameter
String as parameter