a我考网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 98|回复: 1

[考试试题] 2011年JAVA认证模拟题第二阶段(7)

[复制链接]
发表于 2012-8-4 12:33:16 | 显示全部楼层 |阅读模式
  Q19.Given the following hierarchical relationship of several classes.. Z- K" N7 b  W# r0 G
  1. Object" h& o! ~  G2 c/ A+ q" d
  2. |---TypeA6 B  q3 D1 j6 c! b! o
  3. | |-----TypeAB
' f; A! b! N! b  4. | |-----TypeAC
" j7 p( M1 X% W4 q# U  5. |--------TypeY And given the following method definition9 i( N; {) C; l6 A2 ]
  6. public sayType(Object x ){  O  M* X4 r5 P2 E% s) [+ Y
  7. if(x instanceof Object )System.out.print(“Object,”);
& W1 P' b  s4 |% r7 @  8. if(x instanceof TypeA )System.out.print(“TypeA,”);  D/ r; ], i5 C
  9. if(x instanceof TypeAB )System.out.print(“TypeAB,”);9 D. E+ A3 J  k, G  ?' _2 }
  10. if(x instanceof TypeAC )System.out.print(“TypeAC,”);$ ?! l, z) ?  G9 q) g5 {) s
  11. }What would the program output be if the following line was executed
9 V2 \0 e% u( `8 j$ Y  12. sayType( new TypeAB() );
4 o7 q9 ~& h0 O- X9 K7 |; |  a. Object,- A0 P; n! }; X2 G9 r
  b. Object,TypeA,TypeAB,( @% D$ N: N) {4 W
  c. TypeAB,
# p9 H& _. k+ U* V& [  d. Object,TypeAC,
) k. x% ]% T2 _1 C2 [  Q20.What happens on trying to compile and run the following code?
& a; x- U4 K1 {& h9 A  1. public class EqualsTest{
% N- p+ ?% g2 b% T, q  2. public static void main(String args[]){9 B: N2 b" M3 Z1 e+ m) j
  3. Long LA = new Long( 9 ) ;8 r& ~6 q" K+ `% n( N& N8 D. q# Y
3 r$ |; j/ J* ~
  4. Long LB = new Long( 9 ) ;
回复

使用道具 举报

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

2011年JAVA认证模拟题第二阶段(7)

</p>  5. if( LA == LB ) System.out.println(“Equal”);% u5 r4 x/ }8 N
  6. else System.out.println(“Not Equal”);
! Q2 d. X7 y: O7 q  7. }
6 X( X  F% z  k" V* `4 X; H  8. }
: j9 [1 E: n, F5 b  a. The program compiles but throws a runtime exception in line 5.
5 ?0 V$ E% b7 _  b. The program compiles and p rints “Not Equal”., F0 k9 p5 ^6 [
  c. The program compiles and prints “Equal”.' X+ F1 q; H2 r! A* a
  d. The program throws compilation error.+ S6 _, e) e( S7 {* \+ n! |
  Q21.Which one statement in true about the application below?) ^4 q% Z1 T' h
  1. class StaticStuff {+ R) X0 f( Z' i+ `- X
  2. static int x = 10;
7 B( N! J1 y. C; \  3. static { x += 5; }9 ?8 ^% D/ c8 g  q
  4. public s tatic void main(String args[]) {* S* K' ?" M) ^- n: Z
  5. System.out.println(“x = “ + x);
) T% ^8 L3 z9 j4 {& d  6. }
$ \" Q, h: V* [; ?6 X+ G  7. static { x /= 5; }
, [6 x. Y& _  r* c5 I  8. }" W2 c! G* Q) m2 O+ I  Q
  a. The code compiles, and execution produces the output x = 10.9 J) P" B% [  @( o* v3 q# m# V
  b. The code compiles, and execution produces the output x = 15.5 A% H, V. d# d3 `
  c. The code compiles, and execution produces the output x = 3.
! b# I- o5 ~- Q2 \& }  d. Line 7 will not compile, because you can have only one static initializer.
4 `- t( ?& R0 w: f  19. b
0 ~  L4 X/ n' T* j$ `  20. b0 J' k/ w7 W, U9 s9 m
  21. c
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-21 11:22 , Processed in 0.162904 second(s), 23 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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