48、Given the following class:/ o) R! ?- y7 ]: N, b- J; Z
public class Sample{
7 |$ v: b! x: ~5 p% E1 X& D {" ]' X long length;
2 S7 V! A2 a2 R public Sample(long l){ length = l; }7 t4 g- g* r/ Y, w* ]1 W
public static void main(String arg[]){! W" s1 ?3 U6 _: |6 c" E
Sample s1, s2, s3;5 C4 Z) M/ N) G6 k+ F
s1 = new Sample(21L);
1 F! Z4 | h- J" O6 C s2 = new Sample(21L); ! }' \& E e, G% s+ W! g
s3 = s2;
" z. y0 ~: s$ R: Y/ w1 [2 W, @3 N/ G$ D4 P long m = 21L;+ a. t5 U& q) `8 @2 m4 c
}3 I/ |: X, L7 U# p
}& N- V7 X- T- u) X x6 B6 ~( }
Which expression returns true?
) i1 P/ t! D3 IA. s1 == s2;3 l2 o, ~, m# Y
B. s2 == s3;$ p0 \6 H/ H$ U" @
C. m == s1;+ r( c9 ]1 Z* G
D. s1.equals(m).2 b6 [8 l0 ^) O* p
(b)1 R; `; o5 [1 R
题目:给出下面的类:
, u+ b) P/ X% ]/ u8 ?) d# \…4 S0 N4 i y" w: o: Z: a7 k! U6 c
哪个表达式返回true。1 |# i3 M9 p0 e- a; {
前面已经叙述过==操作符和String的equals()方法的特点,另外==操作符两边的操作数必须是同一类型的(可以是父子类之间)才能编译通过。2 F/ M: K' n. Y& \
49、Given the following expression about List.
* m' R; m. v w5 }' A List l = new List(6,true);/ `& T6 Z4 q" B* w, V5 {
Which statements are ture?; a2 V3 [# X7 P" L" s# P# @
A. The visible rows of the list is 6 unless otherwise constrained.
6 z, f. a9 A* C1 eB. The maximum number of characters in a line will be 6., w' ~- c; J: `
C. The list allows users to make multiple selections
( Z c- p8 `* uD. The list can be selected only one item.$ n6 G+ R+ C& `* A' d
(ac)
% ?! f' l T+ D8 i& z题目:给出下面有关List的表达式:( R; Z" _; {( r7 X7 U
… w- M6 t0 u* q/ r: g
哪些叙述是对的。
. t8 ~$ r2 E3 n7 z. zA. 在没有其它的约束的条件下该列表将有6行可见。
; i$ _: w9 H- v9 c( c0 yB. 一行的最大字符数是65 T# Q8 a3 ?# b: {; g, |
C. 列表将允许用户多选。/ Z- E w/ D. K9 Y2 ~# I
D. 列表只能有一项被选中。
9 C9 O2 X; j1 |/ S. }List组件的该构造方法的第一个参数的意思是它的初始显式行数,如果该值为0则显示4行,第二个参数是指定该组件是否可以多选,如果值为true则是可以多选,如果不指定则缺省是不能多选。" [, P9 A, U" `4 B0 J/ }
50、Given the following code:0 p2 A A L7 z( Q$ s8 a
class Person {
+ u B2 |/ u3 k- D+ E( ?0 e String name,department;
, a8 D* E7 W* v" g9 |: y+ g$ ^ public void printValue(){ , l- `6 `( B9 T1 y5 o u
System.out.println("name is "+name);+ `3 }# G. H9 R" M7 M; T
System.out.println("department is "+department);; c8 Y: ^: P& K8 T$ v; z
}6 ?& U- B! q+ d
}
' E& ]( L. u# r# ~; E# L public class Teacher extends Person {( F7 L) k0 d& z+ _& p
int salary;
, [5 \- T. a& M1 ?7 [- e) x9 p public void printValue(){+ O0 Z) V4 i/ ^3 N
// doing the same as in the parent method printValue()% [# {% \3 H9 o) L" w+ t
// including print the value of name and department., F |: r& h: M2 J) h# {; d! B
System.out.println("salary is "+salary);4 n" [. Q/ K0 A
}
' p+ r1 g7 q* o5 P7 i1 | }/ S, f# w1 S% z" d1 e7 R6 U+ w" Q
Which expression can be added at the "doing the same as..." part of the method printValue()?7 u* t( r9 C- C, R( ?* y A5 X" X
A. printValue();# J8 x& e' P$ s8 B$ H( L" K# d
B. this.printValue();0 C- v' n M3 s
C. person.printValue();
9 A9 Q4 G& X% ]1 @) n( N& e+ j8 b4 RD. super.printValue().$ k1 z& I, F7 S W( W
(d)
& p5 \5 p% ~& G题目:给出下面的代码:
$ M# m; t+ P" }0 a…
7 g# [6 w+ R- j1 p" ?# c下面的哪些表达式可以加入printValue()方法的"doing the same as..."部分。, f, O# h& k# y$ G4 K
子类可以重写父类的方法,在子类的对应方法或其它方法中要调用被重写的方法需要在该方法前面加上”super.”进行调用,如果调用的是没有被重写的方法,则不需要加上super.进行调用,而直接写方法就可以。这里要指出的是java支持方法的递归调用,因此答案a和b在语法上是没有错误的,但是不符合题目代码中说明处的要求:即做和父类的方法中相同的事情??打印名字和部门,严格来说也可以选a和b。, M5 T6 _' r- e4 {, o. F
51、Which is not a method of the class InputStream?
% f: T3 D) x O) V) |3 gA. int read(byte[]); D* f4 W7 Q' ~! l( C" @* N# t
B. void flush()+ y6 K+ V1 U. P* a
C. void close()
9 G' a: X& j8 ]# B4 h$ ]D. int available()% p4 N9 p( K [* y/ e
(b)
l; v. @* ` m) k ]( t题目:下面哪个不是InputStream类中的方法 h; D1 w& F& y* L
这个题目没有什么好说的,要求熟悉java API中的一些基本类,题目中的InputStream是所有输入流的父类,所有要很熟悉,参看JDK的API文档。方法void flush()是缓冲输出流的基本方法,作用是强制将流缓冲区中的当前内容强制输出。
- X: |$ P( d' [+ m* Y1 X! P7 V- \52、Which class is not subclass of FilterInputStream?% ]3 j1 {. E4 [+ T
A. DataInputStream, l6 |1 \- \/ y& F$ K
B. BufferedInputStream8 r1 n* c* _+ `: A' a) m
C. PushbackInputStream
; t) p% n9 _2 T. v [D. FileInputStream
; z5 }' W8 L' w5 V) L: x3 e! r(d)
" h* \. H9 k" c! V, G8 a9 b% F题目:
6 d+ o s- S" f哪个不是FilterInputStream的子类。
# t: U0 Q% _3 {此题也是要求熟悉API基础类。Java基础API中的FilterInputStream 的已知子类有:BufferedInputStream, CheckedInputStream, CipherInputStream, DataInputStream, DigestInputStream, InflaterInputStream, LineNumberInputStream, ProgressMonitorInputStream, PushbackInputStream 。
8 v! N9 W0 n# E! V# O53、Which classes can be used as the argument of the constructor of the class FileInputStream?4 F5 W5 r3 P9 _0 L# O2 P* e
A. InputStream8 f: B5 F$ W" }. O& o0 d
B. File
& g% N: t, O. [C. FileOutputStream
O7 L7 I, ?% l+ MD. String$ k+ u9 l$ b! \
(bd)% D+ Q1 F$ |/ G; j
题目:哪些类可以作为FileInputStream类的构造方法的参数。( |+ |' s0 b; T) C$ }
此题同样是要求熟悉基础API,FileInputStream类的构造方法有三个,可接受的参数分别是:File、FileDescriptor、String类的一个对象。0 c4 v* [- Z( Q& Y2 [
54、Which classes can be used as the argument of the constructor of the class FilterInputStream?
+ v; s$ j+ h9 G% lA. FilterOutputStream
`, E% D) ?0 ]6 M" c; x1 `B. File$ g2 Z7 s% E/ b2 z
C. InputStream
( _9 n/ n0 p. {& W" [D. RandomAccessFile
6 f/ h/ Z e: z8 ?7 S6 m, {(c)9 N( b4 K' M5 j, }
题目:哪些类可以作为FilterInputStream类的构造方法的参数。6 j; f+ l$ G7 c1 W/ n
FilterInputStream的构造方法只有一个,其参数是一个InputStream对象。
, _4 e }4 p7 |8 ~55、Given the following code fragment:
: J; a! k) `- O- K9 Z( ?1) switch(m)
7 d c* [; t% B1 B9 j6 i; E2) { case 0: System.out.println("case 0");1 B; q( K5 N7 r9 W" H
3) case 1: System.out.println("case 1"); break;
/ h% X/ Q A) @/ ]( B& Y4) case 2:% |0 R1 z6 \# |9 [ _% G& m4 _. q
5) default: System.out.println("default");5 q* s" o- ~' N+ g
6) }
L- J4 w1 P! s' N3 a1 e+ EWhich value of m would cause "default" to be the output?0 \+ R6 h4 A9 y6 I5 b$ i0 [, k
A. 0
) z9 ~; Y2 C$ `. J FB. 1) v& y" e, @- ?1 n
C. 2
9 Y4 n2 c2 S6 T, n3 E) k# [/ @D. 3" M R( f0 V7 n% q5 f+ \( F, X
(cd)
/ y( @$ c. N3 w: y m/ ~! \题目:给出下面的代码片断:
* I& l2 P4 N' j…
# H: {7 o0 U Q- h$ F% W+ lm为哪些值将导致"default"输出。
5 p8 Q3 {9 N9 Z* b7 _此题考察switch语句的用法,switch的判断的条件必须是一个int型值,也可以是byte、short、char型的值,case中需要注意的是一个case后面一般要接一个break语句才能结束判断,否则将继续执行其它case而不进行任何判断,如果没有任何值符合case列出的判断,则执行default的语句,default是可选的,可以没有,如果没有default而又没有任何值匹配case中列出的值则switch不执行任何语句。
$ D0 B8 m z4 X+ p. k- ?7 u56、Given the uncompleted method:& r. \3 p3 J7 I% a9 H4 ^, k" Y* |. N
1)
% Y$ L* x+ T8 B. b* [0 u2) { success = connect();
" X4 F# o1 }/ V9 p3) if (success==-1) {0 o& c9 y- P4 z; i
4) throw new TimedOutException();0 I+ m6 {0 e# R0 N. L$ o' V& s
5) }3 S' @) Z) a0 y, s7 d
6)}
, i5 `% c' e) T: G# aTimedOutException is not a RuntimeException. Which can complete the method of declaration when added at line 1? t* K& ~- x! D) {
A. public void method()
3 J; n8 p" a8 p. z6 HB. public void method() throws Exception/ M% Q a6 B m! f- ?
C. public void method() throws TimedOutException
5 l4 {& {5 P ?7 I7 k+ X7 R5 ]D. public void method() throw TimedOutException
. |" U9 r) g" i% l# n9 y, O4 SE. public throw TimedOutException void method()8 x# @* W% |5 S5 `( Q0 w. ?& o
(bc)% X6 @8 V) Z. X# C7 R9 I! Z) t0 Q4 W
题目:给出下面的不完整的方法:3 o C( R) Z+ j! L& {, U: l9 |
…2 l* Q1 H7 r' S7 N) M! D9 b4 N3 }
TimedOutException 不是一个RuntimeException。下面的哪些声明可以被加入第一行完成此方法的声明。
+ h' J+ j1 E. |如果程序在运行的过程中抛出异常,而这个异常又不是RuntimeException或者Error,那么程序必须捕获这个异常进行处理或者声明抛弃(throws)该异常,捕获异常可以使用try{}catch(){}语句,而抛弃异常在方法声明是声明,在方法的声明后面加上throws XxxxException,抛弃多个异常时在各异常间使用逗号(,)分隔,题目中的程序在运行时抛出的不是一个RuntimeException,所有必须捕获或者抛弃,而程序又没有捕获,所有应该在方法声明中声明抛弃。由于Exception是所有异常的父类,所有当然也可以代表RuntimeException了。 |