a我考网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 174|回复: 1

[考试试题] Java认证经典模拟试题

[复制链接]
发表于 2012-8-4 12:33:16 | 显示全部楼层 |阅读模式
question 1)
+ L% ]  {+ B( Uwhich of the following lines will compile without warning or error.
( R) n' |% }4 \6 p: Y/ o1) float f=1.3;
. S( e. U, U7 q% b- Q6 i. G2) char c='a';
. @4 H2 j) w: R# G1 q3) byte b=257;
5 @$ k: b2 R3 F/ n. v7 O6 i/ L4) boolean b=null;
5 \" y' \: }% K+ _; U  |5) int i=10; ( Z5 Z) W3 U" ]4 Q
answer to question 1 & P" D, M8 |- ^' O
--------------------------------------------------------------------------------
  ]' A9 d# |( y& R! |question 2)
% x6 Y$ L0 U/ T2 ^3 p& Vwhat will happen if you try to compile and run the following code
3 _. V) G3 g2 f% M) P% {, Tpublic class myclass { / s9 `5 t' S$ |8 e# s
public static void main(string arguments[]) {
1 E0 c- l! q" r( U4 ?amethod(arguments); 5 X5 l9 P6 N1 J' Y
} ( m+ g% V! W* L3 t4 B/ _+ ~
public void amethod(string[] arguments) {
3 h1 _' v# l, N4 H0 S4 @system.out.println(arguments); 2 x8 [  t& n8 V4 m% M6 {3 p- e
system.out.println(arguments[1]); / i% y1 d/ ]& b+ u# V- |
} ! v; A3 [  ^, K1 I$ [% g
} 1 ~4 {* \' s4 {; L& v% z$ x2 s
1) error can´t make static reference to void amethod.
: X+ i/ {, A- Y! `2) error method main not correct
( P8 F$ N  Y. a  R, S3) error array must include parameter
$ a  l- S. L. F  j: E4) amethod must be declared with string
! U0 _* |( N2 T4 q( w& f. Zanswer to question 2
4 s7 E% a  b6 w/ `$ L4 ?4 Z-------------------------------------------------------------------------------- ' t' n4 ]; |5 b' @' f; [7 w
question 3) ; q8 ^' E+ w+ y2 `; C- U& S
which of the following will compile without error
( S2 e9 p" c. T6 q$ G1 X  z+ V1 b1) 2 R! ~2 `' C: z8 n
import java.awt.*; , ?7 W, G% G: ]. I( H% j  x
package mypackage;
; p7 d: J7 {) T! U) o" kclass myclass {} 5 ]& w$ k3 k" e# d) x; Q
2) 9 G: z0 t% v* U/ S& l9 r2 O
package mypackage; 8 U- ^# a2 S3 z. d. P' e( S
import java.awt.*; 8 l7 g2 ~6 n; Z' M
class myclass{} 8 E; s* Z5 i3 K! e2 K
3)
% }$ \: G1 @$ w  t2 T7 \/*this is a comment */ 4 i3 S# L. A$ S- y
package mypackage;
0 u, P$ I) i6 P/ n5 Y. Ximport java.awt.*; ' G) w( |( T# F; M
class myclass{}
( |8 k6 k, @$ K. v" f# F( P' panswer to question 3 ) j' U! _" d' U: v4 t( n/ B
--------------------------------------------------------------------------------
9 q( e3 G8 w6 gquestion 4)
6 R' ?0 k# }0 [$ V, ]" za byte can be of what size
+ y4 b& M0 C& `* Y4 }1) -128 to 127 0 {! q6 j2 m/ i/ [
2) (-2 power 8 )-1 to 2 power 8
) R$ H1 V  [0 ]  q  K& _; O5 N3) -255 to 256
! v4 e7 p8 Y2 J9 ^4)depends on the particular implementation of the java virtual machine
3 C; h4 C( ^& S7 ~$ Z9 }. J; nanswer to question 4 $ J) W( h; U) n4 c
-------------------------------------------------------------------------------- ( Y# |* M  j  ]: K1 U* Z: q4 k( [
question 5) " ^, I! Q: D  U) c/ x( l4 H
what will be printed out if this code is run with the following command line? - {6 t$ A2 ]7 t# T$ x+ _  B
java myprog good morning & G$ l' M1 I9 C3 F3 b0 H
public class myprog{
' }+ _) U( [2 a9 ^- X' Npublic static void main(string argv[])
5 M7 Y6 z# i8 @& F) V' w{ . N# R# ?2 b; q) B
system.out.println(argv[2]) 1 l( u! W+ M( N. x" ?  B
} % T+ H2 ~' D$ f, q5 y- g# P  x3 H9 {
} ; Y, k* i& `1 f6 T- o+ y& G2 |
1) myprog
! m) Y8 h5 I5 p1 n2) good 0 L: e% c7 n8 a0 [" \4 r
3) morning % v6 {" ]; x& D- E, O- {8 K6 Y
4) exception raised: 'java.lang.arrayindexoutofboundsexception: 2' 4 K5 q- L8 w- G! K9 g) i, p
answer to question 5
/ }" O, x; r' D; S-------------------------------------------------------------------------------- & u* y) W2 N+ x2 u
question 6) , e) X. v( j! ~: T
which of the following are keywords or reserved words in java? 2 o, `7 I: a2 J* w% o
1) if
# H2 T2 ]+ V6 z% \: y2) then 0 j' ^  N' e. H* x+ p
3) goto
& D6 G; O+ d: I5 ]1 o" |4) while
* b3 }/ |  q; ]$ `$ Y1 k) d- v4 l, ^' f2 |  D' }6 Z$ R9 u
which of the following statements are true? + I0 e  `: F  m, e0 x" j
1) methods cannot be overriden to be more private 8 H. z  `0 W2 K7 y7 T9 ]
2) static methods cannot be overloaded
6 R5 d% g+ i% f+ w0 @- e! h7 g3) private methods cannot be overloaded
/ V9 }! G! @9 c  U9 w! g) S9 }4) an overloaded method cannot throw exceptions not checked in the base class
/ q) Z* n) c- H( W, {$ C, Z0 [answer to question 16
' \( h2 N, e. \--------------------------------------------------------------------------------
回复

使用道具 举报

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

Java认证经典模拟试题

question 17)
( s$ Q9 u1 ?$ o/ q! r; m, T9 Q% C" m# Ewhat will happen if you attempt to compile and run the following code?
; b' \/ U) O/ p4 @9 Y( Rclass base {} $ t/ r5 }1 [# g) y2 f1 V
class sub extends base {}
- M" w" b7 j  o0 Y0 K7 hclass sub2 extends base {} 6 U8 w' {- _; |! ?" \$ n
public class cex{
; x6 [7 @$ z3 }% v7 c; m% Q  kpublic static void main(string argv[]){ ) A" s: a7 k( r0 t3 H# O
base b=new base(); ( y( Y* Z" r, U+ p
sub s=(sub) b; 6 E6 f0 [) C$ @/ y0 c
}
, U3 j/ O/ P. O# K! O6 R}
. Y9 ^% ^* C& A5 Z( e* R1) compile and run without error
9 W' Q2 P- D6 \( T% O3 C7 f2) compile time exception 8 h: E5 ~; F, f$ L9 b' T
3) runtime exception </p>answer to question 17
7 \  \2 J; V; w4 l" T8 ^" t7 o% o2 {5 b
-------------------------------------------------------------------------------- 0 z9 t1 R9 T6 W2 ~+ _1 b9 S
question 18)
7 z6 j. M: g5 e. Q2 [which of the following statements are true? ! J. U: ^5 u* K. i+ d. X) a
1) system.out.println( -1 >>> 2);will output a result larger than 10 . i/ m% ?. {9 H' `
2) system.out.println( -1 >>> 2); will output a positive number , Q7 p9 k# V; E% y' X& Z
3) system.out.println( 2 >> 1); will output the number 1
' ~$ p2 q) f/ P* b5 K4) system.out.println( 1
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-22 08:28 , Processed in 0.197675 second(s), 23 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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