java软件工程师笔试题目(III) 规则: 1. 时间:40分钟 2. 个人独立完成,不能使用手机等上网上查询。如果被发现作弊,则零分。 3. 为了环保和节约纸张,请在答题卡上填写答案 一、不定项选择题(每题5分) Question 1 Given: 11. public class Test {
; x S) V/ ?/ c0 T' |8 T `/ \3 j12. public static void main(String [] args) {
! @; `: c2 s- N13. int x =5; 6 d* m2 H6 c+ N4 f. `
14. boolean b1 = true; # S" y4 B; v& ~$ g
15. boolean b2 = false; , O' F# W$ [( a9 I* O
17.if((x==4) && !b2) ! P! @* X2 k, u5 Q- R
18. System.out.print(”l “);
/ u2 ]" E+ l( Y/ \2 p, |4 }19. System.out.print(”2 “);
) O& K8 M+ M3 c. i3 m6 @20. if ((b2 = true) && b1)
. P+ z! t6 G9 } x) W" h: F" }+ U; X21. System.out.print(”3 “);
0 |1 T& c) G. o# t8 L" y8 ]% f) l22. } ' ]& D; D0 {/ k2 q$ A2 _
23. } 5 p# Y* L" d7 L8 }# C1 A
What is the result? . X9 o, o( ]; d6 h
A. 2
8 Z4 _: N0 A: d" G% w, LB. 3
! \. h5 @0 u& Y5 FC. 1 2 , U. v5 O6 _2 t! C
D. 2 3
+ d9 D( G, ^- q) o" H: zE. 1 2 3 . D/ U' F1 y5 F! u, Q. c
F. Compilation fails.
+ A: `: K$ ?& G1 L% U, MG. Au exceptional is thrown at runtime. Question 2 Assume that country is set for each class. Given: 10. public class Money {
! \: f: g- ?" j; L11. private String country, name; ) m; B8 v, B" Q0 \3 s
12. public String getCountry() { return country; }
8 u* t" E7 F+ |9 W13.} and: 24. class Yen extends Money {
& |# r6 ]8 d3 a6 q) O: E* O25. public String getCountry() { return super.country; }
* I3 {. {* D6 n1 x26. } 2 G; a7 t- @/ t3 W, h0 x
27. 6 V0 u; ?& Q H8 U* H
28. class Euro extends Money { " @8 @/ m: t# s7 T7 N0 c( D9 D2 ~
29. public String getCountry(String timeZone) {
* M# Y( z3 p; T7 p; \30. return super.getCountry(); 3 z9 N, t1 j* @, R, O
31. }
* U6 |+ p& j' v: T a32. }
5 B# ^ L9 l0 x" ?* fWhich two are correct? (Choose two.) A. Yen returns correct values. ; G( k- `9 O3 O
B. Euro returns correct values.
6 l' |9 V' b& z9 v% ?C. An exception is thrown at runtime. " \! ~/ N& K0 b* c: i( C* f
D. Yen and Euro both return correct values.
2 L* m$ ]) F3 [* X N& Q1 ^E. Compilation fails because of an error at line 25.
! k& z. i( L, L+ K- LF. Compilation fails because of an error at line 30. Question 3 Given: 1. class TestA { ( F( W5 {+ M/ l5 o& V4 W
2. public void start() { System.out.println(”TestA”); } # m6 u+ Q K: A* {$ H; j( c
3. }
( }# \. i* g* r: W! J6 }7 r3 v4. public class TestB extends TestA {
0 S& l! k8 b3 P2 C5. public void start() { System.out.println(”TestB”); }
2 w( I- @6 z# E% P) W. e6. public static void main(String[] args) {
" C. U; {/ q8 x! q7. ((TestA)new TestB()).start(); ! m9 {+ K8 i. x H* V" ?
8. } , g& z! ~ N$ [4 W
9. } % |& L% W1 }. a) J2 w( y+ n
What is the result? A. TestA + R4 i' m2 k; q; v
B. TestB 7 \) W$ \* r7 Z& E. G2 ^
C. Compilation fails. 4 m3 U- t0 `2 f9 m: K/ p6 H U: p
D. An exception is thrown at runtime. Question 4 Given: 11. public static void main(String[] args) {
& \( P+ A) R5 q, @12. String str = “null’; . n3 W- @' d/ q# d( `3 k4 ]
13. if (str == null) {
& F" L I( H' J5 B: y# P* Q14. System.out.println(”null”); ; x$ J; A" O! [5 ~# S
15. } else (str.length() == 0) {
H. t. l u1 U$ o16. System.out.println(”zero”);
! W Y* h; R( v$ e17. } else {
# }% _" t% x5 L: J& f8 q- i! {18. System.out.println(”some”);
# \6 C/ Y/ M6 W7 E- f19. } * h: R" l* T) F3 s' S) L% u* e
20. }
$ m0 D* [" Q" ^7 ~) d3 N‘What is the result? A. null 2 n# C' d* M! p; R: n$ w& N. W+ x
B. zero
8 f( K& ~6 p0 w$ GC. some
3 x, C; R- K8 j( RD. Compilation fails.
( j: C! b, R, H( G9 p) H5 G; UE. An exception is thrown at runtime. Question 5 Given: 33. try { 6 z4 ?- P( p" T3 c- q% F. k# l
34. // some code here
7 {* s! S/ A7 O) {35. } catch (NullPointerException e1) { 7 S6 P8 r1 L# g; _# L4 s8 _% N
36. System.out.print(”a”);
. }' q m+ O; i# j- |37. } catch (RuntimeException e2) { : f6 j% l8 Q6 H. g1 I" r
38. System.out.print(”b”); " j6 H/ d) F2 U- F. ]3 [
39. } finally {
8 G5 T& M9 U* S8 w8 G40. System.out.print(”c”); ) j4 y1 M, i' g
41. } ' A6 A8 Z' T/ N/ |$ u
What is the result if a NullPointerException occurs on line 34?
" X) `* f; H9 XA. c
% O: F$ }% F! f7 aB. a
! }. u# `& {1 n2 EC. ab ! d. j4 ^; |/ d( Z) B
D. ac
. J! F- l5 o/ a* [E. bc
% E) p# U. m! v9 k bF. abc Question 6 Given this method in a class: 21. public String toString() { # |# g1 p6 X% J+ N2 a
22. StringBuffer buffer = new StringBuffer(); & G! \! x# i! v" w8 F
23. buffer.append(’<’);
3 d0 R; ]; ?, \7 V8 N8 d: Z24. buffer.append(this.name); 3 T" D! b4 l5 x: p' ~/ l5 {
25. buffer.append(’>’);
0 S0 o0 T8 [1 v- H9 ^4 o: u26. return buffer.toString();
* T* R. P$ u8 V2 O6 b4 U27. } 6 R/ `* u4 m `7 G4 b
Which is true? A. This code is NOT thread-safe. 9 y' L0 H" r( P
B. The programmer can replace StringBuffer with StringBuilder with no % c( v. _- @& {
other changes.
# p% M7 r3 Q# v- v3 GC. This code will perform well and converting the code to use
! m$ t7 k1 `, l, G. P8 e/ T) Z# SStringBuilder will not enhance the performance.
3 u3 h. V, c" v( x" X& ^) nD. This code will perform poorly. For better performance, the code 9 C8 e2 R! u( p3 i5 r, E! Y
should be rewritten: return “<“+ this.name + “>”; Question 7 Given: 11. String test= “a1b2c3”; 5 B( M( ~, B8 G& d
12. String[] tokens = test.split(”\\d”); ) k! E" x8 e2 O5 t* a% z0 |0 u
13. for(String s: tokens) System.out.print(s +“ “); + p/ i# U4 x1 v2 `0 [9 V: I e
What is the result? & t9 E: }% X# Z8 @# c' ~. u
A. a b c
" k/ L; |4 r& S6 P8 ^B. 1 2 3 ; n1 ^/ i3 P4 T+ ~2 o$ j3 |6 ? a
C. a1b2c3
$ r# |) j8 G2 a# t* u7 ID. a1 b2 c3 + O# s3 i8 U* ?! r+ J, I
E. Compilation fails.
s% O& W5 e: u! yF. The code runs with no output. % y& ?% W2 r r" P5 N# I; _& e
G. An exception is thrown at runtime. Question 8 Question 9 Question 10 请选择同向的图形: Question 11 Question 12 表USER_INFO的结构如下: 下面那些选项可以插入一行到该表中: A、INSERT INTO USER_INFO(USER_INFO_ID, USER_NAME, PASSWORD) VALUES(null,'BQ','password'); B、INSERT INTO USER_INFO VALUES('helloword_id','BQ','password'); C、INSERT INTO USER_INFO(USER_INFO_ID) VALUES('helloword_id'); D、INSERT INTO USER_INFO(USER_INFO_ID, USER_NAME, PASSWORD) VALUES('helloword_id','BQ','password'); Question 13 下面关于视图说法正确的是: A、一个视图可以作为只读被创建。 B、一个视图可以用来连接两个或者更多的表而创建。 C、一个视图在select语句中不能有一个order by 语句。 D、一个视图在select语句中不能同group by 语句一起创建。 E、一个视图必须在select语句中为列名定义别名。 Question 14 EMPLOYEES表数据如下: 选择下面正确的选项: A、SELECT * FROM EMPLOYEES WHERE SALARY>(SELECT MIN(SALARY) FROM EMPLOYEES GROUP BY DEPARTMENT); B、SELECT * FROM EMPLOYEES WHERE SALARY>(SELECT MIN(SALARY) FROM EMPLOYEES GROUP BY DEPARTMENT); C、SELECT * FROM EMPLOYEES WHERE SALARY>(SELECT MIN(SALARY) FROM EMPLOYEES); D、SELECT * FROM EMPLOYEES WHERE SALARY>ALL(SELECT SALARY FROM EMPLOYEES); Question 15 STUDENTS表为空表,添加主键STUDENT_ID列,那个选项能完成这个任务: A、ALTER TABLE STUDENTS ADD PRIMARY KEY STUDENT_ID; B、ALTER TABLE STUDENTS ADD CONSTRAINT PRIMARY KEY (STUDENT_ID); C、ALTER TABLE STUDENTS ADD CONSTRAINT STUD_ID_KEY PRIMARY KEY (STUDENT_ID); D、ALTER TABLE STUDENTS ADD CONSTRAINT STUD_ID_KEY PRIMARY KEY STUDENT_ID; Question 16 一个学生只能就读于一个班级,而一个班级可以同时容纳多个学生,学生与班级之间是()的关系。 A、一对一 B、一对多 C、 多对一 D、多对多
, h7 P3 [8 k/ ]9 L/ F |