a我考网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 88|回复: 0

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

[复制链接]
发表于 2012-8-4 12:33:16 | 显示全部楼层 |阅读模式
module 1 – getting started
2 w& E! J  z- p# d! Wq1.what will happen when you compile and run the following code? 7 L" O1 c7 K1 s: G& M4 B0 H
(4)- b3 y1 ?: p& @% i) Z7 j
public class myclass{
( J  W/ ^1 Z& J5 R$ L" m) A# k+ estatic int i;
/ c4 j6 p3 l, U6 Npublic static void main(string argv[]){
; R# a$ y( o, Z' @& Psystem.out.println(i);
% q* P! [4 B" m0 A}4 R0 \5 A6 X8 U4 b) i2 f2 v
}
, X- ~. Z3 ~6 s! l5 w: ?5 f1) error variable i may not have been initialized
$ R# X0 M. A' k, t. ]2) null
% v+ E) g7 O8 U: j. u3) 1
  `" r( l" @' y& U4) 0
* a4 N  R% E6 Pq2.which of the following will compile without error (2)(3)8 z, Y' E& L0 \0 N1 b+ L+ k6 U
1)
, p2 p+ D+ L; {( T4 Ximport java.awt.*;1 J  M. t3 O# K( t2 S: w
package mypackage;1 ^& P! c2 a! g1 Q' l3 |
class myclass {}6 ]$ L% ^0 ^: n8 s% I8 ]- S
2) 2 m8 o! ?0 s- [# p
package mypackage;% N. e2 d& l& d6 n2 g
import java.awt.*;2 a4 o9 M) V8 M# T7 e
class myclass{}
/ E$ E  V8 h# L. `5 ?3)
: B0 s9 g0 x# R/*this is a comment */" |8 q5 F9 L# X* S6 X8 B/ H
& E% d  [( b; _+ g# U
package mypackage;
4 U7 j* N; Z! \0 e8 Iimport java.awt.*;
/ H2 d3 Y7 P" N9 n% cclass myclass{} q3.what will happen if you try to compile and run the following code (1)
8 R; d: k: P3 t" e- w$ k8 xpublic class myclass {
, \! S1 j1 x- x3 v9 ^1 Y2 }public static void main(string arguments[]) {2 K2 e9 T  ~4 O+ B1 M) w/ T* ^
amethod(arguments);
. ~! Z( g- ]3 K, V0 p/ B}: c/ x6 w% ~! g% b+ m9 w& h9 L* L
public void amethod(string[] arguments) {# V1 k: X* j# s3 B
system.out.println(arguments);
9 b/ u0 g9 w4 i& D2 D4 s% `system.out.println(arguments[1]);3 Q5 L. O4 h$ `7 i/ ~
}
5 C4 X: @3 Y) ]" j" Y/ w& L( ?}. c/ [6 |# m* k2 S  n* u
1) error can't make static reference to void amethod.
+ @) l2 E, I4 _, z; `" {* P2) error method main not correct + g0 l, i3 i0 v5 k  z. \9 ^2 a
3) error array must include parameter / _/ B- y: C+ u0 P3 [" W8 }
4) amethod must be declared with string+ N) m1 U, N5 z* x: f
q4.given the following code(2)/ k3 o7 V: f: M  D# B& }! a" h
public class sytch{
' _% \, J* b3 C1 Xint x=2000;
4 h$ {6 C* b: X9 Z; [  g" [0 wpublic static void main(string argv[]){
/ {- y8 [$ \) _& V. p  ?system.out.println("ms "+argv[1]+"please pay $"+x);
" s3 `$ W6 i% Z6 R3 @}# M( T/ [7 M/ \! n$ ~/ A, q+ c
what will happen if you attempt to compile and run this code with the command line
2 R7 d. {4 b- Njava sytch jones diggle
) c* E4 \1 o# a# r8 r1) compilation and output of ms diggle please pay $2000
& @& V5 _7 `+ e2 S2) compile time error
; g' X- [& \, [! k: ~2 _3) compilation and output of ms jones please pay $2000
. z7 B- N6 N$ s9 y3 o8 y+ w9 G4) compilation but runtime error" X! [- L+ ~& [2 {# E. O9 Z' \- U
q5.you have a public class called myclass with the main method defined as follows(4)
) S* a! g2 i! f- |4 u& p" N+ kpublic static void main(string parm[]){
& ~7 T3 Z/ Z# g9 G8 y8 b4 R) ?+ Psystem.out.println(parm[0]);# Y7 `: k0 {2 `# c3 y+ H
}  f. W( ^$ S. T# P) V' h& b
if you attempt to compile the class and run the program as follows7 X- {4 \% u3 G) q6 V- X
java myclass hello9 I, `. V! N6 s2 u# J2 c) K
what will happen?4 F% t8 i2 M& |" [+ q
1) compile time error, main is not correctly defined
! G5 S' `% Z+ N: g2) run time error, main is not correctly defined
) U6 e, e& I& I3 B  ?' K) j1 j3) compilation and output of java
5 F0 K( v, ]7 t- Q3 I3 L4) compilation and output of hello
回复

使用道具 举报

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

本版积分规则

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

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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