a我考网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 68|回复: 0

[考试试题] JAVA认证历年真题:SCJP考试真题和解析一(6)

[复制链接]
发表于 2012-8-4 12:33:16 | 显示全部楼层 |阅读模式
 11.Given the following class definition: " j$ v4 l9 H6 l, t
class A{
# y0 c" G( a8 I7 a) _4 yprotected int i;
7 P3 y" M* X: \, d$ aA(int i){ 8 \% `; [  Z6 y: n7 A
this.i=i;
, N1 S; B2 Z6 ^/ y4 v}
2 t9 c0 R: N; g}
  v" Y6 {/ G4 @2 u6 Iwhich of the following would be a valid inner class for this class?
" m1 J& [! c+ l+ C. F7 nSelect all valid answers:
- S8 @( V! Q8 g9 d2 {) a  l& ZA. class B{ - B7 @, I0 h; s5 i" ^
} + m+ {; Y+ u  t
B. class B extends A{ ( \$ U' ?  ]; `3 W# P
} + \- `8 a7 |/ A/ N0 O
C. class B extends A{ : ]9 U6 v5 l/ o3 ~- {! }" ^5 v" ~
B(){System.out.println(“i=”+i);} ) [1 n9 G9 w# d+ P2 ~  H
} 6 V8 F4 O! F, z: t) `
D. class B{ 8 q4 H3 ?' X0 n" ]% J  X+ Q% Q
class A{}
5 \: l8 N$ H7 |/ U4 @3 J9 K}
3 P0 A- C9 n# X1 M1 h( k1 @& g% `: mE. class A{}
' i6 d0 N+ Y* A+ W2 U/ x- a  11。A
: D! a( O( d  X0 `- Y1 b/ i此题考查内部类及关键字“super”的用法。内部类不能与外部类同名。另外,当B继承A时,A中的构造函数是带参数的,B中缺省构造函数的函数体为空;而JAVA编译器会为空构造函数体自动添加语句“super();”调用父类构造函数,更进一步是调用父类的参数为空的构造函数。而父类中没有参数为空的构造函数。# C* h  u& q/ n! V5 l- J* [
  12. Which modifier should be applied to a method for the lock of object this to be obtained prior to excution any of the method body? 7 t7 p6 U* k  |6 F% R* E2 K: O+ g
A. synchronized
& s. B, \( u4 F: H' x% MB. abstract 6 w! d- U* e& U- z- j1 r& m/ H
C. final
3 t8 Z# l+ h' f7 oD. static
4 [/ U  A7 O/ T7 a# x' e& yE. public
: m& M0 D7 P5 _: ~  12。A ! ~7 E3 G" J8 u, [
此关键字可以在两个线程同时试图访问某一数据时避免数据毁损。$ D7 V# M( L6 B" c$ ]" g
  13. The following code is entire contents of a file called Example.java,causes precisely one error during compilation:
, r  n& I3 v; t5 \9 d  K1) class SubClass extends BaseClass{
' B5 K7 J4 U, \1 M/ I" o2) }
# l- W' Y: _2 ]3 A( ?8 v) P3) class BaseClass(){
6 A! Z* D0 ~5 ~* P1 k4) String str;
+ r- _- n! y$ d( k1 ^) f5) public BaseClass(){ # G: Q) d2 t8 F, n# d& H# o8 N: k. h
6) System.out.println(“ok”);}
6 \# I8 |; \" y2 X4 |7) public BaseClass(String s){ ) L; D% n; p# x: z, t. f) F+ w
8) str=s;}}
4 I& k# J, }8 u1 W9) public class Example{ ' q1 k8 _1 A( ^9 k% d, y
10) public void method(){ / G: z$ j) m$ e+ ?
11) SubClass s=new SubClass(“hello”);
$ a: p; M* s0 K2 _+ ?8 h; R12) BaseClass b=new BaseClass(“world”);
9 h# v3 e; l3 S6 V3 F13) } 中华IT学院
& \/ r# O' q7 M3 g# @3 M8 t14) } ) f, M, z9 ^4 Z0 g) Z0 Z
Which line would be cause the error? $ n, W2 ?6 b% B; Y  ]: [
A. 9 B. 10 C. 11 D.12
8 C2 a5 L  l5 Z3 `  13。C ' K7 M* l& ?, h, r9 f
当一个类中未显式定义构造函数时,缺省的构造函数是以类名为函数名,参数为空,函数体为空。虽然父类中的某一构造函数有字符串参数s,但是子类继承父类时并不继承构造函数,所以它只能使用缺省构造函数。故在第11行出错。! G  V' X( p4 I& B, `: q
  14. Which statement is correctly declare a variable a which is suitable for refering to an array of 50 string empty object?
# T7 u; \4 [1 e! d3 H4 tA. String [] a ( I& t3 J8 {6 V8 _
B. String a[]
! m. \# s( [# `; K( N# S3 ~C. char a[][] - O( i" U) u2 d2 M6 Z
D. String a[50]
- i/ }# A3 p; t9 n1 I% O2 [  k. n/ y; QF. Object a[50] 7 D% y3 z( Y/ B/ I$ ~9 M* L- A; j
  14。A、B ( L4 p/ w" S0 J/ W
注意,题中问的是如何正确声明一个一维数组,并非实例化或者初始化数组
4 B2 B# p/ e3 S9 M1 i$ ~8 E  15. Give the following java source fragement:
0 w0 F* v0 p4 u4 R' E) g6 G//point x 9 @5 ~% F% P9 J$ k$ t' \0 e
public class Interesting{ % q+ g4 T% j7 k
//do something
6 L  Q+ T& a! x/ U} * i% k2 p/ y5 e: ^  Z9 }
Which statement is correctly Java syntax at point x?
! p: |1 l8 O2 D" S$ F, P6 o6 yA. import java.awt.*; 2 V8 J8 f8 G$ b( S* N
B.package mypackage
$ [. q+ e: q$ Q3 b8 iC. static int PI=3.14 ' |/ x# k. F- f) i+ s% E: d
D. public class MyClass{//do other thing…} E. class MyClass{//do something…}
# T2 W/ L4 r. O3 b: |2 F
( B" a: A% v( b0 e' T  15。A、E
* |: m. r8 }* j! n5 WX处可以是一个输入,包的定义,类的定义。由于常量或变量的声明只能在类中或方法中,故不能选择C;由于在一个文件中只能有一个public类,故不能选择D。 4 c' [4 x$ ^! i+ ]$ H
  16. Give this class outline: 1 f3 z' I! j) E3 H/ q1 r7 d0 t
class Example{ 3 k9 Z. n+ Z5 e2 h- E4 T
private int x; ! ^. u( O. u) J  M: @" j
//rest of class body…
+ S  ]- O2 j, l9 Q" t# m} ! t/ k, I. z9 n/ P8 d9 d. b" F: p
Assuming that x invoked by the code java Example, which statement can made x be directly accessible in main() method of Example.java?
* ?* o% z" D1 n5 R9 K1 JA. Change private int x to public int x
: F; ?  p9 }  ~7 H5 jB. change private int x to static int x
, q; B# G( T6 R5 G2 HC. Change private int x to protected int x : [! @% n0 _& D0 D. I
D. change private int x to final int x
( @4 a( A3 O1 I& _' O4 m  16。B
8 ~4 d4 N0 O; j% ~8 X静态方法除了自己的参数外只能直接访问静态成员。访问非静态成员,必须先实例化本类的一个实例,再用实例名点取。
  W5 J( J1 A6 F% Y4 O7 I) o  17. the piece of preliminary analsis work describes a class that will be used frequently in many unrelated parts of a project 7 P$ F! q0 F! T1 R3 P! Y$ M
“The polygon object is a drawable, A polygon has vertex information stored in a vector, a color, length and width.”
1 M  O! c2 g+ E: M' H/ f9 I/ VWhich Data type would be used?
' I( A% |( a- h9 {9 W! I4 O1 qA. Vector % u- M( L/ C, p( ~$ ^6 V, v
B. int
% }$ m) V2 I( I" l6 n3 D0 |C. String * g; K7 [1 i. w7 f3 s
D. Color
7 X! z9 c7 b- C% X4 B/ M- r5 e8 m/ M" tE. Date
! G) ^1 M: y, J: ~4 f  17。A、B、D ( t4 V1 v# z) B6 L/ p0 x. J
polygon的顶点信息存放在Vector类型的对象内部,color定义为Color,length和width定义为int。
2 Q3 ^* P" ?" a6 q8 P( C  f注意,这是考试中常见的题型。 7 O# ?; C& o: _; E- N% F3 c- _
  18. A class design requires that a member variable should be accessible only by same package, which modifer word should be used? ) z. c7 M5 Q* _) {/ q' M7 d
A. protected 1 [# T% m& _9 z) L6 M
B. public
, M8 j" n; t+ |6 D6 ]C. no modifer 7 m! h7 n& L1 N# d& S+ h# q* O
D. private 1 X' ^2 P3 a% ^6 g
  18。C 8 r" F6 `* e: X5 Y4 r
此题考点是高级访问控制。请考生查阅高级访问控制说明表格。
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-15 19:20 , Processed in 0.218778 second(s), 21 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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