当前位置: 技术问答>java相关
这里的null代表的是Object还是String?
来源: 互联网 发布时间:2015-05-14
本文导语: 这里的null代表的是Object还是String? Q78 What is the result of attempting to compile and run the following program 1. public class Test { 2. public void method(Object o) { 3. System.out.println("Object Version"); 4. } 5. public void m...
这里的null代表的是Object还是String?
Q78
What is the result of attempting to compile and run the following program
1. public class Test {
2. public void method(Object o) {
3. System.out.println("Object Version");
4. }
5. public void method(String s) {
6. System.out.println("String Version");
7. }
8. public static void main(String args[]) {
9. Test test = new Test();
10. test.method(null);
11. }
12. }
Select one correct answer
a. The code does not compile.
b. The code compiles cleanly and shows "Object Version".
c. The code compiles cleanly and shows "String Version".
d. The code throws an Exception at Runtime.
Answer:c
Q79
What is the result of attempting to compile the following program
1. public class Test {
2. public void method(StringBuffer sb) {
3. System.out.println("StringBuffer Verion");
4. }
5. public void method(String s) {
6. System.out.println("String Version");
7. }
8. public static void main(String args[]) {
9. Test test = new Test();
10. test.method(null);
11. }
12. }
Select one correct answer
a. The code does not compile.
b. The code compiles correctly and shows "StringBuffer Version".
c. The code compiles correctly and shows "String Version".
d. The code throws an Exception at Runtime
Answer:a.
Q78
What is the result of attempting to compile and run the following program
1. public class Test {
2. public void method(Object o) {
3. System.out.println("Object Version");
4. }
5. public void method(String s) {
6. System.out.println("String Version");
7. }
8. public static void main(String args[]) {
9. Test test = new Test();
10. test.method(null);
11. }
12. }
Select one correct answer
a. The code does not compile.
b. The code compiles cleanly and shows "Object Version".
c. The code compiles cleanly and shows "String Version".
d. The code throws an Exception at Runtime.
Answer:c
Q79
What is the result of attempting to compile the following program
1. public class Test {
2. public void method(StringBuffer sb) {
3. System.out.println("StringBuffer Verion");
4. }
5. public void method(String s) {
6. System.out.println("String Version");
7. }
8. public static void main(String args[]) {
9. Test test = new Test();
10. test.method(null);
11. }
12. }
Select one correct answer
a. The code does not compile.
b. The code compiles correctly and shows "StringBuffer Version".
c. The code compiles correctly and shows "String Version".
d. The code throws an Exception at Runtime
Answer:a.
|
78) c
按照就"近"原则, 从下到上的顺序. String是Object的子类.所以选String.
79) a
由于StringBuffer 和 String 属于同一级别的类, 编译器不知道该调用哪个函数,所以编译错误.
按照就"近"原则, 从下到上的顺序. String是Object的子类.所以选String.
79) a
由于StringBuffer 和 String 属于同一级别的类, 编译器不知道该调用哪个函数,所以编译错误.