a我考网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 123|回复: 1

[考试试题] JAVA认证历年真题:310-025精选题(42)

[复制链接]
发表于 2012-8-4 12:33:16 | 显示全部楼层 |阅读模式
310-025精选题(42)的具体内容如下:
" _8 p% D) M# a4 o' t5 o190. Consider the following code: What will be printed?
7 e) b" m  B: F1 r/ U# X1 ?public class ExceptionTest2{8 X- ^3 z6 F5 E0 y! E1 c* D5 r
public static void main(String[] args){
! _( j+ [7 M  }1 ~; R3 [ExceptionTest2 e = new ExceptionTest2();
0 R4 R1 Z3 ?3 v3 K! i& J8 Fe.divide(4, 0);}
; w! u4 J! }$ e- \/ wpublic void divide(int a, int b){
, {+ Y, ]: u' h" B9 |6 {. ]try{
8 j/ {4 v  p% T. B! A2 Cint c = a/b;
1 a/ |: e! Z! o7 n7 i}7 i( m  w" S, A& Z) T, U2 }
catch(ArithmeticException e){
# v; V! w  f; i2 gSystem.out.println("ArithmeticException");* K/ z+ P# _4 k2 v) [& W
}
: g# E, G, ?6 V% b, Ocatch(RuntimeException e){1 }' H" _" I, _- b% B6 d
System.out.println("RuntimeException");
( y1 @/ P9 z( ~}/ R! P" }. Z4 v+ X
catch(Exception e){
1 L+ a2 k- s' s% t+ O& F. F/ ESystem.out.println("Exception");
2 _( a0 V% m  ~! N3 F7 ^' o& J}
% r6 S# h0 f0 Q: l) G) {: pfinally{& M4 K( q: }( K/ e$ Y1 U% q. ~
System.out.println("Finally");* G. [0 Z, \) A0 X6 d# t1 a2 M& Y
}
5 K7 m: M5 ~7 x0 m. X& r}8 E  ~* `: @. b, c
} A. ArithmeticException: C5 E- s, j% ~
B. RuntimeException
6 r8 ]8 @% a$ b! M9 S& rC. Exception
( C3 m+ L) ^/ x. a. K, ^$ y5 E2 E# PD. Finally
8 u& [, R4 V! H5 u1 F; [  N' IA. ArithmeticException D. Finally.
" {) B# a/ E6 u7 |# l' J5 U! `# h- b6 ^" G, O" s4 a
191. Consider the following code: What will be printed?6 e5 p" |3 L$ }3 F6 H
public class ExceptionTestMindQ{
9 N% q; x, A# _4 P4 T5 q9 p  M! u1 ]. cpublic static void main(String [] args){
; R; T7 x8 ?& L2 _1 ?0 e& tExceptionTestMindQ e = new ExceptionTestMindQ();$ s% ^4 Z( r' l9 y2 }' A
e.trythis();
. k  D) F$ q# d* j, l2 B" R}
# B1 l% K1 Z8 k* J5 D2 U1 cpublic vo id trythis(){5 Y" ?0 j  v/ L3 G: l+ C1 z
try{
3 Y; M. h0 ~# T9 VSystem.out.println("Innan testet");
  b$ }. |! m' r0 p: a' D' g4 K2 x7 @problem();
  x2 B  v+ q; b7 |( Z* [}  M1 @+ A' Z3 i3 M5 q/ L# `
catch (NullPointerException x){" ~' e+ f4 H% C1 g
System.out.println("Nullpointer");
0 L# r- F* n2 \9 w& |}; ?7 L4 L; A, E- L" |3 z
catch(Exception x){, H- g5 B: r' d; M
System.out.println("Exception");
回复

使用道具 举报

 楼主| 发表于 2012-8-4 12:33:17 | 显示全部楼层

JAVA认证历年真题:310-025精选题(42)

return;</p>}" C1 A. U2 M) v. [  N3 _
finally{% b+ i3 o2 Q3 P3 g+ Y
System.out.println("finally");# K8 Y, k* k$ M! c/ \: e
}' R' u" F6 W* y1 {: Y9 R' J
System.out.println("mymethod is done");2 ^* d+ Y2 f' I* h5 O
}' p% \7 q$ K! }; D; l" [
public void problem()throws IllegalArgumentException{
, ^+ i7 z; Z7 N& k' d, N3 rthrow new IllegalArgumentException();
- v9 X% X& B: Z+ g. J) u/ Q# S& e}' B6 I. Q/ K7 S/ c; m
}
7 B) C7 C+ f4 e* N& M. ^6 f* x, A) z+ W( \! n9 c
A.Innan testet& N+ G+ ?# @/ ~  H
A.Nullpointer&acute;
8 B; M+ A) l' k' e$ {8 }9 _/ lB.Exception
  q+ `9 v8 m. |# d) WC.finally3 j" v, I, q( g; M& ]
D.mymethod is done
& H* P/ ]: J/ p$ DA. Innan testet C. exception D. finally.
: ~7 B8 Z( P  g192. Consider the following code: What will be printed?
1 U& b' O: K8 _0 {$ qpublic class exceptiontest101{6 _# s9 N: s; ~
public static void main(String[]args){# Y% P6 O% J& m! O; u* c0 i% M
exceptiontest101 e = new exceptiontest101();
6 q4 G9 t% M6 w; ie.myMethod();) T) e3 A* }& @$ D0 W8 m/ H
}* G- |# P$ n9 W1 b8 G1 U
void myMethod(){
' G" G2 N( _& l  R, @3 @& M5 @try{
. }# f2 T% p* s6 l' x: a* Ifragile() ;
/ z& K( K1 Q6 s; H}; F0 ~' b. \% }! q1 D  ^
catch(NullPointerException npex){  q4 o' Z4 H! {2 B
System.out.println("NullPointerException thrown ");
6 B0 v+ h$ F9 O) v; m}
; i0 E; q- }% r6 o- p' `catch(Exception ex){
- U: o4 x2 @4 j7 B0 ^( T" bSystem.out.println("Exception thrown ");! E: v6 L7 ^7 E* g+ P
}6 _3 r; q; A) o
finally{: ~. ~- {: n  E1 R) |
System.out.println("Done with exceptions ");! q$ {" z- w0 Z: `
}3 M# `& _7 h2 E! A: t
System.out.println("myMethod is done");4 J: w3 C' ?* T- A
}: m+ o7 c  B! j9 k# I9 R9 i: I
public void fragile() {7 u1 D. N# K: x. v. x3 u2 f
throw new IllegalArgumentException();* p) h& w' i# g- D$ I" d
}7 v2 F2 y5 e9 ?; b) A7 {1 j
}
  `2 |( c/ F$ A) c: IE.NullpointerException thrown
+ {1 V" i: {. i( I8 q$ C0 O8 v, m/ `F.Exception thrown
' |" ~1 J" x* C/ y1 s/ p( w+ H! ^G.Done with exceptions
0 V3 @) g4 H+ TH.D.myMethod is done
$ n% \' w# J0 ^$ t$ OB. Exception thrown C. Done with exceptions D. myMethod is done
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Woexam.Com ( 湘ICP备18023104号 )

GMT+8, 2024-6-4 17:19 , Processed in 0.173711 second(s), 24 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表