java软件工程师笔试题目(III) 规则: 1. 时间:40分钟 2. 个人独立完成,不能使用手机等上网上查询。如果被发现作弊,则零分。 3. 为了环保和节约纸张,请在答题卡上填写答案 一、不定项选择题(每题5分) Question 1 Given: 11. public class Test { ! D7 h1 z& f% [( g$ P. A
12. public static void main(String [] args) {
9 B% X: `2 w, s, d8 p6 i% [13. int x =5; v+ e/ v+ s* f+ ?
14. boolean b1 = true; 5 i+ t& F& `7 {9 N' O. Y
15. boolean b2 = false; 5 t" s* O9 e& m* q5 G- j# j/ O
17.if((x==4) && !b2)
+ g# g& [5 W: R4 |. N, v18. System.out.print(”l “); , k5 l! i& F# t7 }, W
19. System.out.print(”2 “); 9 i9 z8 A; u! l! F7 Z8 q% b
20. if ((b2 = true) && b1)
& u) L, C+ _; w+ J1 X! x# i2 ]21. System.out.print(”3 “); % Q* V/ X, b ?" J
22. } * H9 Y8 H3 X: m% r" S5 q
23. }
g2 g+ _/ E9 }( o3 W5 HWhat is the result? 2 Z( Q/ ^- G0 U1 P
A. 2 ; f. X0 V# a% c: ~ R8 L' N$ f5 J
B. 3
W9 ]" _# n; a; j2 ?! u; MC. 1 2 - g7 v0 ]" k5 s; U8 `$ W8 ]
D. 2 3 * e: @, h& [ Q3 h/ N6 Y
E. 1 2 3
. D( E! F4 q1 r: U5 [F. Compilation fails.
2 ] a, y* d S$ f0 R& [( @! d" hG. Au exceptional is thrown at runtime. Question 2 Assume that country is set for each class. Given: 10. public class Money { 9 ^9 ^+ P# t9 b+ n
11. private String country, name; 4 d' L) y( W6 M- K1 [6 K
12. public String getCountry() { return country; }
, j6 p0 a. A- e, E- w. l5 l13.} and: 24. class Yen extends Money { 7 j) e0 G7 O2 Q4 I" E
25. public String getCountry() { return super.country; }
! V% t) X. y" `* S/ D2 w6 c26. }
" \5 S1 b* ^+ V6 z4 g' Y1 l27.
0 W9 B1 `- [; @4 d2 |/ j4 O) Q3 s: j28. class Euro extends Money {
9 g8 ]3 E9 g8 J29. public String getCountry(String timeZone) { & A8 s9 \1 O- ?: K$ C& n
30. return super.getCountry();
; ]7 }4 b1 u2 j! _3 l x# B31. } : k& F3 F! F8 q! ^! F
32. } # w' h# J7 t* \9 G \" { T
Which two are correct? (Choose two.) A. Yen returns correct values.
! [9 Z# u5 z, k$ eB. Euro returns correct values. 8 Z5 T* Y9 k0 }
C. An exception is thrown at runtime.
- L1 I& w6 ^. [- j" F5 D! F: sD. Yen and Euro both return correct values. " e2 @5 A. H& {4 c
E. Compilation fails because of an error at line 25.
8 P0 m9 s' a. k# vF. Compilation fails because of an error at line 30. Question 3 Given: 1. class TestA { u9 t: \2 _6 W! X1 R* C
2. public void start() { System.out.println(”TestA”); } 1 u v; D) q% o' J; m
3. } ) Q$ q- O Q3 w3 R# R" u
4. public class TestB extends TestA { 8 `# U6 ]3 i" F
5. public void start() { System.out.println(”TestB”); } ; O4 f8 `6 q" Z6 X3 ^* X+ Y
6. public static void main(String[] args) { $ F2 L0 |- X0 c) ^1 W
7. ((TestA)new TestB()).start(); ) ^3 s1 g0 z, e/ H
8. } & i6 ]: j' M8 K) `" w+ r" A
9. } / k5 o- i1 G: i( d. |
What is the result? A. TestA
' H' x8 \3 b ?0 ]) {* B8 @8 C0 h+ z% dB. TestB ( _* ^$ P9 |9 ?( H4 K! |
C. Compilation fails.
. m" ^7 K& J- C# }) kD. An exception is thrown at runtime. Question 4 Given: 11. public static void main(String[] args) { % l9 R& x; p8 i9 d8 |7 C
12. String str = “null’;
* o8 ], R7 J2 ~1 a3 ]13. if (str == null) { 6 |+ O/ X& x/ N& I% |" v, t
14. System.out.println(”null”);
6 {% P# U( @# C15. } else (str.length() == 0) {
$ l8 p1 R6 D! j& D* U* i H16. System.out.println(”zero”);
1 b% @! M- a. J3 j# t( J* N17. } else {
6 S+ v/ _3 E# H! n* M# `' L9 S# w18. System.out.println(”some”);
; w$ S& R; b$ u+ m! P D19. } 1 c" u! d9 j# {# {7 D( U
20. }
" K9 s* B x" J7 ^# C$ v‘What is the result? A. null 4 i3 [/ Z2 T& Z
B. zero , n0 U, A9 P1 H% c+ I! B5 u- U7 R
C. some ( c! v' ~0 k" T
D. Compilation fails.
- x' C7 {6 U2 L/ F ?E. An exception is thrown at runtime. Question 5 Given: 33. try { 7 [5 [, C% C! u9 ^+ Q' G( _
34. // some code here 1 i, `. t/ j) m% N& B
35. } catch (NullPointerException e1) { , j, d# o! T( L
36. System.out.print(”a”);
2 {% l. v5 l. G/ Z% n37. } catch (RuntimeException e2) {
9 r4 Y& B* q/ R- O+ ]' M38. System.out.print(”b”);
) C9 @5 u3 p" L8 [: _1 k: B39. } finally {
+ w- q9 V5 L% w5 J; W; ]$ _40. System.out.print(”c”); 4 h6 q# g+ k% f; T; K# S( @
41. }
( g, _; |# J/ d5 ?2 G nWhat is the result if a NullPointerException occurs on line 34? ( ?/ t% F! l2 c4 w# \, W
A. c
3 b& S' }7 V _& p. dB. a
+ l7 I" ?& k' Z6 t2 A {C. ab
; J/ L4 U9 y/ z% [- T9 s1 Z1 o) LD. ac " M/ Y8 I, C e/ W" f# C% S
E. bc Y; O5 G( X: n9 C, g; I
F. abc Question 6 Given this method in a class: 21. public String toString() {
& F# a4 n4 V7 M22. StringBuffer buffer = new StringBuffer();
6 V( c$ d" p% J7 A/ J! A# Z23. buffer.append(’<’);
1 n- k! @5 V# r24. buffer.append(this.name);
+ i Z5 t3 c& f; ]# A25. buffer.append(’>’); 5 [4 p% e4 i9 \# Q" k
26. return buffer.toString();
8 L3 c! b$ j6 p& Y4 _3 ?9 U27. } , I. r9 a4 D! |% ]% a* ?
Which is true? A. This code is NOT thread-safe. ; @8 ^: L/ Y' Z* t# m
B. The programmer can replace StringBuffer with StringBuilder with no
& j, \8 L, Z" K: s! Pother changes. 2 }3 M6 {2 C' j/ C
C. This code will perform well and converting the code to use
5 U u0 s' A4 R$ W: C* c7 P9 V3 k; oStringBuilder will not enhance the performance. ! N* b' K# e. Z' ^2 P5 y
D. This code will perform poorly. For better performance, the code
9 J. h5 G2 q( w* _should be rewritten: return “<“+ this.name + “>”; Question 7 Given: 11. String test= “a1b2c3”; 2 Y4 y3 Z* o9 c+ p# ~6 }) C# ~
12. String[] tokens = test.split(”\\d”); # g$ C2 C p7 A( j# ~) ?
13. for(String s: tokens) System.out.print(s +“ “); 3 Y/ E# n5 B1 D0 q
What is the result?
! M. r4 I% E- B$ V, c5 L6 oA. a b c
- k. j6 v: T; _9 vB. 1 2 3
1 d7 R0 u8 o$ T% ^# W- L$ |% |C. a1b2c3 / A# J3 b ` Q `5 o$ `
D. a1 b2 c3
L8 t8 b. T5 D( u- ?" YE. Compilation fails.
9 t w9 Y$ Y0 r% mF. The code runs with no output. + r) S5 F9 C, o; ~0 t5 S% Q' ^4 p$ d4 u
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、多对多
4 e8 D! }* q4 C, U |