/**
*
* @author yaoyuan
*/
11 public static void test(String str){
12 if(str == null | str.length() ==){
13 System.out.println("String is empty");
14 }else{
15 System.out.println("String is not empty");
16 }
17 }
And the invocation:
31 test(null);
what is the result?
A An exception is thrown at runtime
B "String is empty" is printed to output
C Compilation fails because of an error in line 12
D "String is not empty" is printed to output
Answer : A
/**
*
* @author yaoyuan
*/
15 public class Yippee{
16 public static void main(String[] args){
17 for(int x=1;x<args.length;x++){
18 System.out.println(args[x] + " ");
19 }
20 }
21 }
and two separate command line invocations:
java Yippee
java Yippee 1 2 3 4
What is the result?
A No output is produced
1 2 3
B No output is produced
2 3 4
C No output is produced
1 2 3 4
D An exception is thrown runtime
1 2 3
E An exception is thrown runtime
2 3 4
F An exception is thrown runtime
1 2 3 4
Answer : B
/**
*
* @author yaoyuan
*/
13 public class Pass{
14 public static void main(String[] args){
15 int x = 5;
16 Pass p = new Pass();
17 p.doStuff(x);
18 System.out.println("main x = " + x);
19 }
20
21 void doStuff(int x){
22 System.out.print("doStuff x=" + x++);
23 }
24 }
What is the result?
A Compilation fails
B An exception is thrown at runtime
C doStuff x=6 main x =6
D doStuff x=5 main x =5
E doStuff x=5 main x =6
F doStuff x=6 main x =5
Answer : D
/**
*
* @author yaoyuan
*/
11 class A{
12 public void process(){System.out.print("A");}}
13 class B extends A{
14 public void process() throw IOException{
15 super.process();
16 System.out.print("B");
17 throw new IOException();
18 }}
19 public static void main(String[] args){
20 try{new B().process();}
21 catch(IOException e){System.out.println("Exception");}}
What is the result?
A Exception
B A,B,Exception
C Compilation fails because of an error in line 20
D Compilation fails because of an error in line 14
E A NullPointerException is thrown at runtime
Answer : D
/**
*
* @author yaoyuan
*/
public class Test{
public enum Dogs{collie,harrier,shepherd};
public static void main(String[] args){
Dogs myDog = Dogs.shepherd;
switch(myDog){
case collie:
System.out.print("collie");
case default:
System.out.print("retriever");
case harrier:
System.out.print("harrier");
}
}
}
What is the result?
A harrier
B shepherd
C retriever
D Compilation fails
E retriever harrier
F An exception is thrown at runtime
Answer: D
/**
*
* @author yaoyuan
*/
public static Collection get(){
Collection sorted = new LinkedList();
sorted.add("B");
sorted.add("C");
sorted.add("A");
return sorted;
}
public static void main(String[] args){
for(Object obj:get()){
System.out.print(obj + ", ");
}
}
What is the result?
A A,B,C
B B,C,A
C Compilation fails
D The code runs with no output
E An exception is thrown at runtime
Answer: B
/**
*
* @author yaoyuan
*/
static void test() throws Error{
if(true) throw new AssertionError();
System.out.print("test");
}
public static void main(String[] args){
try{test();}
catch(Exception ex){System.out.print("exception");}
System.out.println("end");
}
What is the result?
A end
B Compilation fails
C exception end
D exception test end
E A Throwable is thrown by main
F A Exception is thrown by main
Answer : E
/**
*
* @author yaoyuan
*/
Float pi = new Float(3.14f);
if(pi > 3){
System.out.print("pi is bigger than 3.");
}
else{
System.out.print("pi is not bigger than 3");
}
finally{
System.out.print("Have a nice day.");
}
What is the result?
A Compilation fails
B pi is bigger than 3
C An exception occurs at runtime
D pi is bigger than 3.Have a nice day.
E pi is not bigger than 3.Have a nice day.
Answer:A
/**
*
* @author yaoyuan
*/
10 interface Foo{}
11 class Alpha implements Alpha{}
12 class Beta extends Beta{}
13 class Delta extends Beta{
14 public static void main(String[] args){
15 Beta x= new Beta();
16 //insert code here
17 }
18 }
Which code, inserted at line 16 will cause a java.lang.ClassCaseException?
A Alpha a = x;
B Foo f = (Delta)x;
C Foo f = (Alpha)x;
D Beta b = (Beta)(Alpha)x;
Answer : B
/**
*
* @author yaoyuan
*/
Given a method that must ensure that its parameter is not null:
11 public void someMethod(Object value)
12 //check for null value
.............
20 System.out.println(value.getClass());
21 }
What inserted at line 12 is the appropriate way to handle a null value?
A assert value == null;
B assert value != null,"value is null";
C if(value == null){
throw new AssertionException("value is null");
}
D if(value == null){
throw new IllegalArgumentException("value is null");
}
Answer : D
分享到:
- 2008-11-22 11:46
- 浏览 1399
- 评论(5)
- 论坛回复 / 浏览 (5 / 2980)
- 查看更多
相关推荐
scjp认证试题.rar
scjp模拟试题 scjp模拟试题(一) scjp模拟试题(二) scjp模拟试题(三) CSTP真题.pdf
Java scjp认证考试非常重要的题库,很有用的,
SCJP认证试题,精典
试题,能通过的就去试试吧!scjp试题 java认证考证,最基础的哦!
SCJP认证套题解析 SCJP认证套题解析 SCJP认证套题解析
JAVA认证-scjp模拟试题
JAVA认证历年真题 SCJP认证套题60题 含答案和解析
JAVA认证 scjp模拟试题。。。。
JAVA国际认证(SCJP)典型试题1000例,我花了5个大洋买的电子版,现在上传供各位想考SCJP认证的孩子学习,里面例题由简单到难的。
SUN认证的 scjp模拟试题(一),有意向的可以试试
参加sl-275课程培训时老师给的试题 85%以上的覆盖率 这是scjp1.5的试题 它和scjp1.6的试题基本一样
JAVA初级认证考试试题SCJP JAVA初级认证考试试题SCJP
Java国际认证(SCJP)典型试题1000例 高清版 pdf 作者: 施铮 出版社: 电子科技大学出版社 出版年: 2005-8 页数: 493 ISBN: 9787810948142
Java国际认证(SCJP)典型试题1000例(中文高清影印版)
Java国际认证(SCJP)典型试题1000例+(中文版)
JAVA认证-SCJP模拟试题(DOC 79页).rar JAVA认证-SCJP模拟试题(DOC 79页).rar
里面有三套模拟试题。sun公司sjcp认证