a我考网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 109|回复: 0

[考试试题] 关于JAVA的五道经典模拟题

[复制链接]
发表于 2012-8-4 12:33:16 | 显示全部楼层 |阅读模式
module 1 – getting started# ~8 l  x6 L; m- z. C$ i% t
q1.what will happen when you compile and run the following code?
! N, R; Q' M. L3 v& ~! I(4)
- ^/ @$ B' u) |& t4 X9 I1 n% fpublic class myclass{# C, r6 ?7 Z" f# o7 K7 k
static int i;. J6 l* ~# X3 M4 F1 @, f% R% C* t
public static void main(string argv[]){" o( Z  Y  U8 J/ ^% z- Y
system.out.println(i);
- i2 p; Q) x! Z7 L3 h}7 p$ u- F# W  G; Q
}
  B. @7 V" j4 }. R1) error variable i may not have been initialized $ E: I: v+ r  ?: f* L7 Z
2) null 1 n! {0 m* {; G+ N! x
3) 1 + W& q0 W+ p9 B3 T: x0 t
4) 0
% o# O( s1 ?9 L+ u8 D: P# `q2.which of the following will compile without error (2)(3)
; E/ j: a' P4 b8 O) X% w1)
% R2 k2 n! Z6 w0 y* Y* h" \0 Mimport java.awt.*;
& O2 h4 x' k  |5 n: ]0 ]package mypackage;
( g2 [% n3 j! Q, _* H0 |class myclass {}( E! m6 l1 N6 \
2) + b9 E* i$ Y/ m
package mypackage;5 n+ S' k7 S" Y6 d* \8 o: \
import java.awt.*;: D; K6 I% B2 x+ ]
class myclass{}1 }  L& }5 L9 u8 w
3)
: |6 z2 W2 c5 w) L/*this is a comment */
! D% q/ {# J4 k& ~: N* ^
" ~6 I, Q5 j* cpackage mypackage;
7 \, V0 U/ f6 l$ Zimport java.awt.*;
1 I' C( m) K- z/ `, v( dclass myclass{} q3.what will happen if you try to compile and run the following code (1); N. c  f! Z3 v! Q- a" ~# Y5 ^
public class myclass {
) Z) [5 e8 {& j! G2 ?public static void main(string arguments[]) {6 C. g4 Z9 H& B8 X
amethod(arguments);5 m  K# O& I- H1 T+ ?% `; l4 E
}
+ V" u* [& N( `, m2 c3 ^6 fpublic void amethod(string[] arguments) {8 n, v' w8 q% `1 H$ B
system.out.println(arguments);
$ u- a$ P3 H# Msystem.out.println(arguments[1]);) U9 _! L: ?2 i3 v2 F+ p
}0 R7 q; d/ o4 Z" x) `# u: H) B( G( `
}
9 ^/ ^( J9 i7 B- q" r' V' H1) error can't make static reference to void amethod.
* \, ]& _( b+ _- U! j+ |; W2) error method main not correct
4 J  {  U/ O0 |; |# b% J3 W# g3) error array must include parameter
- O- x- X, L0 b- {9 S1 j5 _# `( m4) amethod must be declared with string6 X8 O! Z- _, n# T# I& f
q4.given the following code(2)
' o2 U! c9 X7 _9 w+ u  qpublic class sytch{
3 K& U) w' u& A7 o, \/ eint x=2000;" j% m" V2 s1 w( Z
public static void main(string argv[]){
1 v8 T7 Q: n  T; ]/ X  X; b- ksystem.out.println("ms "+argv[1]+"please pay $"+x);7 C( K/ p* d7 h
}
4 a' @$ R- B4 |% iwhat will happen if you attempt to compile and run this code with the command line
$ C' `; r# g* Y# [java sytch jones diggle0 |1 S2 |% W; ^. _7 I2 C
1) compilation and output of ms diggle please pay $2000  R9 m+ ?4 O2 Y) q4 w
2) compile time error" H9 P) L4 M/ r- g& ]* u! B
3) compilation and output of ms jones please pay $20002 ]0 ?$ G* H+ h8 a
4) compilation but runtime error
1 S( Z5 @( t2 Y. v9 ^& c2 yq5.you have a public class called myclass with the main method defined as follows(4)' I) h1 G- U  i0 ]6 E
public static void main(string parm[]){' n7 Y0 G2 R- ?
system.out.println(parm[0]);
% `3 O  p. B& g! T0 g( X+ Z( Y+ u( R}
# f/ a1 h" z" S# M6 ?/ q. Pif you attempt to compile the class and run the program as follows/ [, A+ O# G  M9 ^& z8 B9 {
java myclass hello' g6 L% _6 }/ V6 Z' s6 R; m6 b
what will happen?
; j5 V$ M  J+ C& M- Y8 ]/ f1) compile time error, main is not correctly defined
4 p; m( ?3 N( c. b/ a) b2) run time error, main is not correctly defined
7 P5 m* a; F7 y' f6 f2 N9 O3) compilation and output of java7 y0 t" v# L7 c  |. I4 a; l" a$ M
4) compilation and output of hello
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-22 10:34 , Processed in 0.271182 second(s), 21 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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