当前位置:首页 > 精选30道Java笔试题解答
1.下列 java 程序输出结果为______。 1 2 3 4 A.
true,false
int i=0;
Integer j = new Integer(0); System.out.println(i==j); System.out.println(j.equals(i));
B. true,true C. false,true D. false,false
E. 对于不同的环境结果不同
F. 程序无法执行
2.下列java程序的输出结果为____。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 A.
public class Example{
String str=new String(\
char[]ch={'a','b'};
public static void main(String args[]){
Example ex=new Example(); ex.change(ex.str,ex.ch);
System.out.print(ex.str+\
Sytem.out.print(ex.ch);
}
public void change(String str,char ch[]){
str=\ ch[0]='c';
} }
hello and ab
B. hello and cb C. hello and a D. test ok and ab E. test ok and cb
F. test ok and c
3.有关下述Java代码描述正确的选项是____。
1
public class TestClass {
2 3 4 5 6 7 8 A.
private static void testMethod(){
System.out.println(\
}
public static void main(String[] args) { ((TestClass)null).testMethod();
} }
编译不通过
B. 编译通过,运行异常,报NullPointerException C. 编译通过,运行异常,报IllegalArgumentException D. 编译通过,运行异常,报NoSuchMethodException E. 编译通过,运行异常,报Exception
F. 运行正常,输出testMethod
4.结构型模式中最体现扩展性的几种模式是()
A. 装饰模式 B. 合成模式 C. 桥接模式
D. 适配器
5.以下java程序代码,执行后的结果是()
1 2 3 4 A. 0 B. null C. 1
D. 2
6. 以下java程序代码,执行后的结果是()
1 2 3
java.util.HashMap map=new java.util.HashMap();
map.put(\ map.put(\ System.out.println(map.size());
public class Test {
public static void main(String[] args) {
Object o = new Object() {
4 5 6 7 8 9 10 A. B. true
public boolean equals(Object obj) {
return true;
} };
System.out.println(o.equals(\
}
}
Fred
C. 编译错误 D. 运行时抛出异常
7. 代码片段:
1 2 3 4 5
byte b1=1,b2=2,b3,b6; final byte b4=4,b5=6;
b6=b4+b5; b3=(b1+b2);
System.out.println(b3+b6);
关于上面代码片段叙述正确的是() A.
输出结果:13
B. 语句:b6=b4+b5编译出错 C. 语句:b3=b1+b2编译出错 D. 运行期抛出异常
8. 下面代码运行结果是()
1 2 3 4 5 6 7 8 9 10 11 12 13
public class Test{
public int add(int a,int b){
try {
return a+b;
}
catch (Exception e) {
System.out.println(\语句块\
}
finally{
System.out.println(\语句块\
}
14 15 16 17 18
return 0;
}
public static void main(String argv[]){
Test test =new Test();
System.out.println(\和是:\
}
}
A. catch语句块,和是:43 B. 编译异常
C. finally语句块,和是:43
D. 和是:43,finally语句块
9. 执行以下程序后的输出结果是()
1 2 3 4 5 6 7 8 9 10 11 A. A,A B. A,B C. B,B D. AB,B
10. 如何处理循环引用问题?
11. 下面所示的java代码,运行时,会产生()类型的异常 1
public class Test {
public static void main(String[] args) { StringBuffer a = new StringBuffer(\ StringBuffer b = new StringBuffer(\
operator(a, b);
System.out.println(a + \ + b);
}
public static void operator(StringBuffer x, StringBuffer
y) {
x.append(y); y = x;
} }
int Arry_a[] = new int[10];
共分享92篇相关文档