SCJP认证试题及答案

上传人:wu****ei 文档编号:155945360 上传时间:2022-09-25 格式:DOC 页数:34 大小:69.01KB
收藏 版权申诉 举报 下载
SCJP认证试题及答案_第1页
第1页 / 共34页
SCJP认证试题及答案_第2页
第2页 / 共34页
SCJP认证试题及答案_第3页
第3页 / 共34页
资源描述:

《SCJP认证试题及答案》由会员分享,可在线阅读,更多相关《SCJP认证试题及答案(34页珍藏版)》请在装配图网上搜索。

1、转载 对题目和答案谨做参考Q1 A method is . 1) an implementation of an abstraction. 2) an attribute defining the property of a particular abstraction. 3) a category of objects. 4) an operation defining the behavior for a particular abstraction. 5) a blueprint for making operations. Q2 An object is . 1) what class

2、es are instantiated from. 2) an instance of a class. 3) a blueprint for creating concrete realization of abstractions. 4) a reference to an attribute. 5) a variable. Q3 Which line contains a constructor in this class definition? public class Counter / (1) int current, step; public Counter(int startV

3、alue, int stepValue) / (2) set(startValue); setStepValue(stepValue); public int get() return current; / (3) public void set(int value) current = value; / (4) public void setStepValue(int stepValue) step = stepValue; / (5) 1) Code marked with (1) is a constructor 2) Code marked with (2) is a construc

4、tor 3) Code marked with (3) is a constructor 4) Code marked with (4) is a constructor 5) Code marked with (5) is a Constructor Q4 Given that Thing is a class, how many objects and reference variables are created by the following code? Thing item, stuff; item = new Thing(); Thing entity = new Thing()

5、; 1) One object is created 2) Two objects are created 3) Three objects are created 4) One reference variable is created 5) Two reference variables are created 6) Three reference variables are created. Q5 An instance member 1) is also called a static member 2) is always a variable 3) is never a metho

6、d 4) belongs to a single instance, not to the class as a whole 5) always represents an operation Q6 How do objects pass messages in Java? 1) They pass messages by modifying each others member variables 2) They pass messages by modifying the static member variables of each others classes 3) They pass

7、 messages by calling each others instance member methods 4) They pass messages by calling static member methods of each others classes. Q7 Given the following code, which statements are true? class A int value1; class B extends A int value2; 1) Class A extends class B. 2) Class B is the superclass o

8、f class A. 3) Class A inherits from class B. 4) Class B is a subclass of class A. 5) Objects of class A have a member variable named value2. Q8 If this source code is contained in a file called SmallProg.java, what command should be used to compile it using the JDK? public class SmallProg public sta

9、tic void main(String args) System.out.println(Good luck!); 1) java SmallProg 2) avac SmallProg 3) java SmallProg.java 4) javac SmallProg.java 5) java SmallProg main Q9 Given the following class, which statements can be inserted at position 1 without causing the code to fail compilation? public class

10、 Q6db8 int a; int b = 0; static int c; public void m() int d; int e = 0; / Position 1 1) a+; 2) b+; 3) c+; 4) d+; 5) e+; Q10 Which statements are true concerning the effect of the and operators? 1) For non-negative values of the left operand, the and operators will have the same effect. 2) The resul

11、t of (-1 1) is 0. 3) The result of (-1 1) is -1. 4) The value returned by will never be negative as long as the value of the right operand is equal to or greater than 1. 5) When using the operator, the leftmost bit of the bit representation of the resulting value will always be the same bit value as

12、 the leftmost bit of the bit representation of the left operand. Q11 What is wrong with the following code? class MyException extends Exception public class Qb4ab public void foo() try bar(); finally baz(); catch (MyException e) public void bar() throws MyException throw new MyException(); public vo

13、id baz() throws RuntimeException throw new RuntimeException(); 1) Since the method foo() does not catch the exception generated by the method baz(), it must declare the RuntimeException in its throws clause. 2) A try block cannot be followed by both a catch and a finally block. 3) An empty catch blo

14、ck is not allowed. 4) A catch block cannot follow a finally block. 5) A finally block must always follow one or more catch blocks. Q12 What will be written to the standard output when the following program is run? public class Qd803 public static void main(String args) String word = restructure; Sys

15、tem.out.println(word.substring(2, 3); 1) est 2) es 3) str 4) st 5) s Q13 Given that a static method doIt() in a class Work represents work to be done, what block of code will succeed in starting a new thread that will do the work? CODE BLOCK A: Runnable r = new Runnable() public void run() Work.doIt

16、(); ; Thread t = new Thread(r); t.start(); CODE BLOCK B: Thread t = new Thread() public void start() Work.doIt(); ; t.start(); CODE BLOCK C: Runnable r = new Runnable() public void run() Work.doIt(); ; r.start(); CODE BLOCK D: Thread t = new Thread(new Work(); t.start(); CODE BLOCK E: Runnable t = n

17、ew Runnable() public void run() Work.doIt(); ; t.run(); 1) Code block A. 2) Code block B. 3) Code block C. 4) Code block D. 5) Code block E. Q14 Write a line of code that declares a variable named layout of type LayoutManager and initializes it with a new object, which when used with a container can

18、 lay out components in a rectangular grid of equal-sized rectangles, 3 components wide and 2 components high. Q15 public class Q275d static int a; int b; public Q275d() int c; c = a; a+; b += c; public static void main(String args) new Q275d(); 1) The code will fail to compile, since the constructor

19、 is trying to access static members. 2) The code will fail to compile, since the constructor is trying to use static member variable a before it has been initialized. 3) The code will fail to compile, since the constructor is trying to use member variable b before it has been initialized. 4) The cod

20、e will fail to compile, since the constructor is trying to use local variable c before it has been initialized. 5) The code will compile and run without any problems. Q16 What will be written to the standard output when the following program is run? public class Q63e3 public static void main(String

21、args) System.out.println(9 2); 1) 81 2) 7 3) 11 4) 0 5) false Q17 Which statements are true concerning the default layout manager for containers in the java.awt package? 1) Objects instantiated from Panel do not have a default layout manager. 2) Objects instantiated from Panel have FlowLayout as def

22、ault layout manager. 3) Objects instantiated from Applet have BorderLayout as default layout manager. 4) Objects instantiated from Dialog have BorderLayout as default layout manager. 5) Objects instantiated from Window have the same default layout manager as instances of Applet. Q18 Which declaratio

23、ns will allow a class to be started as a standalone program? 1) public void main(String args) 2) public void static main(String args) 3) public static main(String argv) 4) final public static void main(String array) 5) public static void main(String args) Q19 Under which circumstances will a thread

24、stop? 1) The method waitforId() in class MediaTracker is called. 2) The run() method that the thread is executing ends. 3) The call to the start() method of the Thread object returns. 4) The suspend() method is called on the Thread object. 5) The wait() method is called on the Thread object. Q20 Whe

25、n creating a class that associates a set of keys with a set of values, which of these interfaces is most applicable? 1) Collection 2) Set 3) SortedSet 4) Map Q21 What does the value returned by the method getID() found in class java.awt.AWTEvent uniquely identify? 1) The particular event instance. 2

26、) The source of the event. 3) The set of events that were triggered by the same action. 4) The type of event. 5) The type of component from which the event originated. Q22 What will be written to the standard output when the following program is run? class Base int i; Base() add(1); void add(int v)

27、i += v; void print() System.out.println(i); class Extension extends Base Extension() add(2); void add(int v) i += v*2; public class Qd073 public static void main(String args) bogo(new Extension(); static void bogo(Base b) b.add(8); b.print(); 1) 9 2) 18 3) 20 4) 21 5) 22 Q23 Which lines of code are

28、valid declarations of a native method when occurring within the declaration of the following class? public class Qf575 / insert declaration of a native method here 1) native public void setTemperature(int kelvin); 2) private native void setTemperature(int kelvin); 3) protected int native getTemperat

29、ure(); 4) public abstract native void setTemperature(int kelvin); 5) native int setTemperature(int kelvin) Q24 How does the weighty property of the GridBagConstraints objects used in grid bag layout affect the layout of the components? 1) It affects which grid cell the components end up in. 2) It af

30、fects how the extra vertical space is distributed. 3) It affects the alignment of each component. 4) It affects whether the components completely fill their allotted display area vertically. Q25 Which statements can be inserted at the indicated position in the following code to make the program writ

31、e 1 on the standard output when run? public class Q4a39 int a = 1; int b = 1; int c = 1; class Inner int a = 2; int get() int c = 3; / insert statement here return c; Q4a39() Inner i = new Inner(); System.out.println(i.get(); public static void main(String args) new Q4a39(); 1) c = b; 2) c = this.a;

32、 3) c = this.b; 4) c = Q4a39.this.a; 5) c = c; Q26 Which is the earliest line in the following code after which the object created on the line marked (0) will be a candidate for being garbage collected, assuming no compiler optimizations are done? public class Q76a9 static String f() String a = hell

33、o; String b = bye; / (0) String c = b + !; / (1) String d = b; b = a; / (2) d = a; / (3) return c; / (4) public static void main(String args) String msg = f(); System.out.println(msg); / (5) 1) The line marked (1). 2) The line marked (2). 3) The line marked (3). 4) The line marked (4). 5) The line m

34、arked (5). Q27 Which methods from the String and StringBuffer classes modify the object on which they are called? 1) The charAt() method of the String class. 2) The toUpperCase() method of the String class. 3) The replace() method of the String class. 4) The reverse() method of the StringBuffer clas

35、s. 5) The length() method of the StringBuffer class. Q28 Which statements, when inserted at the indicated position in the following code, will cause a runtime exception when attempting to run the program? class A class B extends A class C extends A public class Q3ae4 public static void main(String a

36、rgs) A x = new A(); B y = new B(); C z = new C(); / insert statement here 1) x = y; 2) z = x; 3) y = (B) x; 4) z = (C) y; 5) y = (A) y; Q29 Which of these are keywords in Java? 1) default 2) NULL 3) String 4) throws 5) long Q30 It is desirable that a certain method within a certain class can only be

37、 accessed by classes that are defined within the same package as the class of the method. How can such restrictions be enforced? 1) Mark the method with the keyword public. 2) Mark the method with the keyword protected. 3) Mark the method with the keyword private. 4) Mark the method with the keyword

38、 package. 5) Do not mark the method with any accessibility modifiers. Q31 Which code fragments will succeed in initializing a two-dimensional array named tab with a size that will cause the expression tab32 to access a valid element? CODE FRAGMENT A: int tab = 0, 0, 0 , 0, 0, 0 ; CODE FRAGMENT B: in

39、t tab = new int4; for (int i=0; i CODE FRAGMENT C: int tab = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ; CODE FRAGMENT D: int tab32; CODE FRAGMENT E: int tab = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ; 1) Code fragment A. 2) Code fragment B. 3) Code fragment C. 4) Code fragment D. 5) Code fragment E

40、. Q32 What will be the result of attempting to run the following program? public class Qaa75 public static void main(String args) String arr = , null , 1, 2 , 1, null, 3 , , 1, null ; System.out.println(arr.length + arr12.length); 1) The program will terminate with an ArrayIndexOutOfBoundsException.

41、 2) The program will terminate with a NullPointerException. 3) 4 will be written to standard output. 4) 6 will be written to standard output. 5) 7 will be written to standard output. Q33 Which expressions will evaluate to true if preceded by the following code? String a = hello; String b = new Strin

42、g(a); String c = a; char d = h, e, l, l, o ; 1) (a = Hello) 2) (a = b) 3) (a = c) 4) a.equals(b) 5) a.equals(d) Q34 Which statements concerning the following code are true? class A public A() public A(int i) this(); class B extends A public boolean B(String msg) return false; class C extends B priva

43、te C() super(); public C(String msg) this(); public C(int i) 1) The code will fail to compile. 2) The constructor in A that takes an int as an argument will never be called as a result of constructing an object of class B or C. 3) Class C has three constructors. 4) Objects of class B cannot be const

44、ructed. 5) At most one of the constructors of each class is called as a result of constructing an object of class C. Q35 Given two collection objects referenced by col1 and col2, which of these statements are true? 1) The operation col1.retainAll(col2) will not modify the col1 object. 2) The operati

45、on col1.removeAll(col2) will not modify the col2 object. 3) The operation col1.addAll(col2) will return a new collection object, containing elements from both col1 and col2. 4) The operation col1.containsAll(Col2) will not modify the col1 object. Q36 Which statements concerning the relationships bet

46、ween the following classes are true? class Foo int num; Baz comp = new Baz(); class Bar boolean flag; class Baz extends Foo Bar thing = new Bar(); double limit; 1) A Bar is a Baz. 2) A Foo has a Bar. 3) A Baz is a Foo. 4) A Foo is a Baz. 5) A Baz has a Bar. Q37 Which statements concerning the value

47、of a member variable are true, when no explicit assignments have been made? 1) The value of an int is undetermined. 2) The value of all numeric types is zero. 3) The compiler may issue an error if the variable is used before it is initialized. 4) The value of a String variable is (empty string). 5)

48、The value of all object variables is null. Q38 Which statements describe guaranteed behavior of the garbage collection and finalization mechanisms? 1) Objects are deleted when they can no longer be accessed through any reference. 2) The finalize() method will eventually be called on every object. 3)

49、 The finalize() method will never be called more than once on an object. 4) An object will not be garbage collected as long as it is possible for an active part of the program to access it through a reference. 5) The garbage collector will use a mark and sweep algorithm. Q39 Which code fragments wil

50、l succeed in printing the last argument given on the command line to the standard output, and exit gracefully with no output if no arguments are given? CODE FRAGMENT A: public static void main(String args) if (args.length != 0) System.out.println(argsargs.length-1); CODE FRAGMENT B: public static vo

51、id main(String args) try System.out.println(argsargs.length); catch (ArrayIndexOutOfBoundsException e) CODE FRAGMENT C: public static void main(String args) int ix = args.length; String last = argsix; if (ix != 0) System.out.println(last); CODE FRAGMENT D: public static void main(String args) int ix

52、 = args.length-1; if (ix 0) System.out.println(argsix); CODE FRAGMENT E: public static void main(String args) try System.out.println(argsargs.length-1); catch (NullPointerException e) 1) Code fragment A. 2) Code fragment B. 3) Code fragment C. 4) Code fragment D. 5) Code fragment E. Q40 Which of the

53、se statements concerning the collection interfaces are true? 1) Set extends Collection. 2) All methods defined in Set are also defined in Collection. 3) List extends Collection. 4) All methods defined in List are also defined in Collection. 5) Map extends Collection. Q41 What is the name of the meth

54、od that threads can use to pause their execution until signalled to continue by another thread? Fill in the name of the method (do not include a parameter list). Q42 Given the following class definitions, which expression identifies whether the object referred to by obj was created by instantiating

55、class B rather than classes A, C and D? class A class B extends A class C extends B class D extends A 1) obj instanceof B 2) obj instanceof A & ! (obj instanceof C) 3) obj instanceof B & ! (obj instanceof C) 4) obj instanceof C | obj instanceof D 5) (obj instanceof A) & ! (obj instanceof C) & ! (obj

56、 instanceof D) Q43 What will be written to the standard output when the following program is run? public class Q8499 public static void main(String args) double d = -2.9; int i = (int) d; i *= (int) Math.ceil(d); i *= (int) Math.abs(d); System.out.println(i); 1) 12 2) 18 3) 8 4) 12 5) 27 Q44 What wi

57、ll be written to the standard output when the following program is run? public class Qcb90 int a; int b; public void f() a = 0; b = 0; int c = 0 ; g(b, c); System.out.println(a + + b + + c0 + ); public void g(int b, int c) a = 1; b = 1; c0 = 1; public static void main(String args) Qcb90 obj = new Qc

58、b90(); obj.f(); 1) 0 0 0 2) 0 0 1 3) 0 1 0 4) 1 0 0 5) 1 0 1 Q45 Which statements concerning the effect of the statement gfx.drawRect(5, 5, 10, 10) are true, given that gfx is a reference to a valid Graphics object? 1) The rectangle drawn will have a total width of 5 pixels. 2) The rectangle drawn w

59、ill have a total height of 6 pixels. 3) The rectangle drawn will have a total width of 10 pixels. 4) The rectangle drawn will have a total height of 11 pixels. Q46 Given the following code, which code fragments, when inserted at the indicated location, will succeed in making the program display a button spanning the whole window area? import java.awt.*; public class Q1e65 public static void main(String args) Window win = new Frame(); Button but = new Button(button); / insert code fragmen

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!