a我考网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 90|回复: 0

[考试试题] JAVA试题:五道经典JAVA模拟题

[复制链接]
发表于 2012-8-4 12:33:16 | 显示全部楼层 |阅读模式
module 1 – getting started/ L9 n/ A0 ?- S( R: \
q1.what will happen when you compile and run the following code? ( Z) r# ~' {; B7 s# A
(4)% G! N  F+ w# i
public class myclass{4 S' ~3 [" G/ Q
static int i;
9 R5 b. S! u8 P$ F5 Dpublic static void main(string argv[]){
0 d0 o& I4 g- [2 b& Csystem.out.println(i);
/ O7 X6 A2 K- N7 p; y  M( C( u}$ D' r" M  W5 C
}8 c/ x9 M# ]- ~
1) error variable i may not have been initialized
8 b, J5 W. _& d' `4 U8 {; \9 S2) null
* \8 \2 J' }  d/ M" G3) 1 0 Q- {" ]9 i( n2 Z7 [1 C( z
4) 0
0 b1 B9 }, I1 L* g" hq2.which of the following will compile without error (2)(3)0 P8 [' f# V( v, q, v) o4 a
1)
" U( V! |0 S1 t% b. fimport java.awt.*;% \/ n& x" D- J2 k
package mypackage;) X0 R$ ~: f* \- W% r/ }( ~
class myclass {}
4 ^2 Q: {. s) ]( a1 g$ w; ^  Q2)
. l0 D% y8 w5 _' [4 w3 spackage mypackage;
, w: [, n3 Q* y% E. J5 x6 ?, Vimport java.awt.*;
( a6 q. [+ V- v/ `. T/ dclass myclass{}
, w$ {8 p% U4 f$ M3) 9 U7 a9 a' W, g( _/ n
/*this is a comment */3 z  D2 A5 ~  M) s: t! X

; r( Q. G$ q9 ~. d: F( U1 P' opackage mypackage;
1 S, t( |8 t+ ?, Oimport java.awt.*;4 j- b( t9 [6 G2 b8 V  ^6 d
class myclass{} q3.what will happen if you try to compile and run the following code (1)
! K3 u; M' Q* k% S# Bpublic class myclass {
1 P8 f% a$ W  c* Y1 Tpublic static void main(string arguments[]) {
" n- @: i" `( J  ]7 Y: e1 k4 Jamethod(arguments);
7 [8 \- K" Q% ~" |}" G- P( P$ f0 B1 U- t5 `( r0 `/ o
public void amethod(string[] arguments) {
0 x$ i& w3 B# v8 {7 jsystem.out.println(arguments);
; ?+ F7 J* k) D: H: |system.out.println(arguments[1]);  k! _3 X/ D6 ?( A' x7 [6 Z& k& [8 d
}# R2 s0 M: |3 M1 p$ n
}9 q/ K0 y& o# [. t. m. k. h
1) error can't make static reference to void amethod. 5 D/ n  W  c& j
2) error method main not correct & d& Y- m5 Y- P$ W  R2 b
3) error array must include parameter
5 }, [3 P" {/ c: Q4) amethod must be declared with string2 [* d) d1 E. P2 H, G9 y% `. r
q4.given the following code(2): }$ b  ^( D2 y7 e$ K
public class sytch{3 R7 j& @0 F$ j7 g, n( S
int x=2000;
- L% X5 d2 ~. ^  u( F! N8 bpublic static void main(string argv[]){2 s9 Y0 `3 G, e/ P/ N" P/ ]
system.out.println("ms "+argv[1]+"please pay $"+x);
. e$ g' B: t* p: h  @}
! ~. i+ B, h+ k# ?8 m5 k8 ^$ ywhat will happen if you attempt to compile and run this code with the command line 2 U4 V5 @$ ^( S( [/ b! m
java sytch jones diggle
9 A  f; v0 u: b  u. H0 o. G) c1) compilation and output of ms diggle please pay $2000
9 _0 i, a. {: C6 Q1 R, G* `  W; ?2) compile time error
' \) u3 o% v" N6 [5 b3) compilation and output of ms jones please pay $2000
/ b, O7 ^' A' p% C  ^- D) O3 l; l( \4) compilation but runtime error/ u  o- u' Q2 @$ i
q5.you have a public class called myclass with the main method defined as follows(4)
$ ?  a" Z3 Q  e/ Spublic static void main(string parm[]){: ]9 p& m4 q/ |1 s( {
system.out.println(parm[0]);, o3 p' x+ _# G" P: ]! l( x$ u
}
3 n3 j, D) a& _if you attempt to compile the class and run the program as follows
2 q+ v# S. B: B9 H& r. U4 D1 Ujava myclass hello" r. @: O0 ^+ @( r
what will happen?
) k. U) ?) R6 G4 \9 U1) compile time error, main is not correctly defined, h9 O, E# i- j8 m
2) run time error, main is not correctly defined' E5 \1 [  Z4 u( b8 ~- Z, f
3) compilation and output of java
/ G) Z  \4 _0 Z3 ?/ _: ^4) compilation and output of hello
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-6-19 02:45 , Processed in 0.206053 second(s), 22 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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