overloading methods# Java - 爪哇娇娃
r*l
1 楼
What is the output of the following code?
01: public class A {
02: public static void test(Object a) {
03: System.out.println("Object");
04: }
05: public static void test(String a) {
06: System.out.println("String");
07: }
08:
09: public static void main(String args[]) {
10: test(null);
11: }
12: }
The answers:
A.Object
B.String
C.Compilation error
D.Runtime error
Answer is B. Why?
01: public class A {
02: public static void test(Object a) {
03: System.out.println("Object");
04: }
05: public static void test(String a) {
06: System.out.println("String");
07: }
08:
09: public static void main(String args[]) {
10: test(null);
11: }
12: }
The answers:
A.Object
B.String
C.Compilation error
D.Runtime error
Answer is B. Why?