續(xù):Java程序員認證模擬題及詳細分析(1) 和(2) (3)
66. Given the following class outline:
class Example{
private int x;
// rest of class body
public static void main(String args[]){
//implementation of main mehtod}
}
Which statement is true?
A. x=2 is a valid assignment in the main() method of class Example.
B. Changing private int x to int x would make x=2 a valid assignment in the main() method of class Example.
C. Changing private int x to public int x would make x=2 a valid assignment in the main() method of class Example.
D. Changing private int x to static int x would make x=2 a valid assignment in the main() method of class Example.
E. Changing class Example to public class Example would make x=2 a valid assignment in the main() method of class Example.
67. Which statement is true about an inner class?
A. It must be anonymous
B. It can not implement an interface
C. It is only accessible in the enclosing class
D. It can access any final variables in any enclosing scope.
68. Which statement is true about the grid bag layout manager?
A. The number of rows and columns is fixed when the container is created.
B. The number of rows and columns is fixed when the GridBagLayout object is created.
C. If a component has a fill value of BOTH, then as the container change size, the component is resized.
D. Every component must carry a non-zero weightx and weighty value when it is added to the container
E. If a row has a weighty value that is non-zero, then as the container changes height, the row changes height.
69. Which statement are true about writing a class that is to handle the events issued by a user interface component.
A. Subclassing an adapter is inappropriate in this case.
B. The class should implement some listener interface
C. A class can implement multiple listener interfaces if desired.
D. A subclass of an AWT component cannot listen to its own events.
E. When implements listener interface, a class need only provide those handler methods that it chooses.
70.The argument for a class?s main() method is called args, and the class is invoked as follows.
java Example cat
What would be the effect of trying to access args[0] in the main method?
A. The value produced is cat
B. The value produced is java
C. The value produced is Example
D. An object of type NullPointerException is thrown.
E. An object of type ArrayIndexOutofBoundsException is thrown.
71. Which best describes the requirements of a fully encapsulated class?
A. Mehtods must not be private.
B. Variables must not be public.
C. The class must be marked final
D. Public methods are all marked final.
E. Modification of the objects state is only possible using method calls.
72.Which contains objects without ordering, duplication, or any particular lookup/retrieval mechanism?
A. Map
B. Set
C. List
D. Collection
E. Enumeration 73.What might cause the current thread to stop executing?
A. An interrupted exception is thrown.
B. The thread execute a sleep() call.
C. The thread constructs a new thread
D. A thread of higher priority becomes ready
E. The thread executes a read() call on InputStream
74.Which statements are true about threads?
A. Threads created from the same class all finish together.
B. A thread can be created only by subclassing java.lang.Thread.
C. Invoking the suspend() method stops a thread so that it cannot be restarted.
D. The Java interpreter?s natural exit occurs when no non-daemon threads remain alive.
E. Uncoordinated changes to shared data by multiple threads may result in the data being read, or left, in an inconsistent state.
75.What might form part of a correct inner class declaration or combined declaration and instantiation?
A. private class C
B. new SimpleInterface(){
C. new ComplexInterface(x){
D. private final abstract class(
E. new ComplexClass() implements SimpleInterface
76. Which statements are true about the garbage collection mechanisms?
A. The garbage collection mechanism release memory at pridictable times.
B. A correct program must not depend upon the timing or order of garbage collection
C. Garbage collection ensures that a program will NOT run out of memory during execution
D. The programmer can indicate that a reference through a local variable is no longer going to be used.
E. The programmer has a mechanism that explicitly and immediately frees the memory used by Java objects.
====================================================
答案及詳細分析:
66.D
main()方法是靜態(tài)方法,靜態(tài)方法不能直接訪問非靜態(tài)成員。
67.D
此題考察學(xué)生對內(nèi)部類屬性的掌握情況。內(nèi)部類可以實現(xiàn)接口;匿名類是內(nèi)部類的一種;內(nèi)部類通過各種方式可以在包含它的類的外部被訪問到;內(nèi)部類被定義在塊中時,只能訪問包含它的塊的final類型變量。故選擇D。
68.C
此題考察考生對類GridBagLayout、及類GridBagConstraints的掌握情況,請考生查閱API文檔。
69.B、C
此題考察考生對事件處理的理解。D選項是錯的,因為控件可以監(jiān)聽自己的事件。另外,當實現(xiàn)一個接口時,必須實現(xiàn)它內(nèi)部的所有的方法,所以E選項也是錯的。
70.A
命令行參數(shù)是緊跟在類名后面的。所以本題中參數(shù)由“cat”提供。
71.E
在完全封裝類中,一般的定義方式是將所有的成員變量定義為“private”,而將訪問這些變量的方法定義為非“private”類型,這樣可以在類的外部間接地訪問這些變量。所以E選項是最符合這個意思的。
72.B
此題考察“Collection API”的一些知識。實現(xiàn)接口“Set”的類內(nèi)部所存儲的對象是沒有順序,但是允許重復(fù)的。另請注意其它幾個接口的特征。
73.A、B、D、E
當新線程被創(chuàng)建時,只是使它變?yōu)榭蛇\行狀態(tài)而已,并不能使當前線程停止執(zhí)行。當調(diào)用read()方法時,它與輸入輸出打交道,可能造成線程的暫停執(zhí)行。
74.D、E
程序的執(zhí)行完畢是以用戶線程(user threads)的結(jié)束而標志結(jié)束的,與超級線程(daemon threads)無關(guān)。所以D選項是對的。E選項說明的是當不同線程對相同數(shù)據(jù)進行訪問時,可能造成數(shù)據(jù)毀損。
75.A、B
76.B、D
程序的代碼是無法對垃圾回收進行精確控制的,程序代碼與垃圾回收是相互獨立的系統(tǒng),并不互相影響。答案D告訴我們程序員可以使一個本地變量失去任何意義,例如給本地變量賦值為“null”;
66. Given the following class outline:
class Example{
private int x;
// rest of class body
public static void main(String args[]){
//implementation of main mehtod}
}
Which statement is true?
A. x=2 is a valid assignment in the main() method of class Example.
B. Changing private int x to int x would make x=2 a valid assignment in the main() method of class Example.
C. Changing private int x to public int x would make x=2 a valid assignment in the main() method of class Example.
D. Changing private int x to static int x would make x=2 a valid assignment in the main() method of class Example.
E. Changing class Example to public class Example would make x=2 a valid assignment in the main() method of class Example.
67. Which statement is true about an inner class?
A. It must be anonymous
B. It can not implement an interface
C. It is only accessible in the enclosing class
D. It can access any final variables in any enclosing scope.
68. Which statement is true about the grid bag layout manager?
A. The number of rows and columns is fixed when the container is created.
B. The number of rows and columns is fixed when the GridBagLayout object is created.
C. If a component has a fill value of BOTH, then as the container change size, the component is resized.
D. Every component must carry a non-zero weightx and weighty value when it is added to the container
E. If a row has a weighty value that is non-zero, then as the container changes height, the row changes height.
69. Which statement are true about writing a class that is to handle the events issued by a user interface component.
A. Subclassing an adapter is inappropriate in this case.
B. The class should implement some listener interface
C. A class can implement multiple listener interfaces if desired.
D. A subclass of an AWT component cannot listen to its own events.
E. When implements listener interface, a class need only provide those handler methods that it chooses.
70.The argument for a class?s main() method is called args, and the class is invoked as follows.
java Example cat
What would be the effect of trying to access args[0] in the main method?
A. The value produced is cat
B. The value produced is java
C. The value produced is Example
D. An object of type NullPointerException is thrown.
E. An object of type ArrayIndexOutofBoundsException is thrown.
71. Which best describes the requirements of a fully encapsulated class?
A. Mehtods must not be private.
B. Variables must not be public.
C. The class must be marked final
D. Public methods are all marked final.
E. Modification of the objects state is only possible using method calls.
72.Which contains objects without ordering, duplication, or any particular lookup/retrieval mechanism?
A. Map
B. Set
C. List
D. Collection
E. Enumeration 73.What might cause the current thread to stop executing?
A. An interrupted exception is thrown.
B. The thread execute a sleep() call.
C. The thread constructs a new thread
D. A thread of higher priority becomes ready
E. The thread executes a read() call on InputStream
74.Which statements are true about threads?
A. Threads created from the same class all finish together.
B. A thread can be created only by subclassing java.lang.Thread.
C. Invoking the suspend() method stops a thread so that it cannot be restarted.
D. The Java interpreter?s natural exit occurs when no non-daemon threads remain alive.
E. Uncoordinated changes to shared data by multiple threads may result in the data being read, or left, in an inconsistent state.
75.What might form part of a correct inner class declaration or combined declaration and instantiation?
A. private class C
B. new SimpleInterface(){
C. new ComplexInterface(x){
D. private final abstract class(
E. new ComplexClass() implements SimpleInterface
76. Which statements are true about the garbage collection mechanisms?
A. The garbage collection mechanism release memory at pridictable times.
B. A correct program must not depend upon the timing or order of garbage collection
C. Garbage collection ensures that a program will NOT run out of memory during execution
D. The programmer can indicate that a reference through a local variable is no longer going to be used.
E. The programmer has a mechanism that explicitly and immediately frees the memory used by Java objects.
====================================================
答案及詳細分析:
66.D
main()方法是靜態(tài)方法,靜態(tài)方法不能直接訪問非靜態(tài)成員。
67.D
此題考察學(xué)生對內(nèi)部類屬性的掌握情況。內(nèi)部類可以實現(xiàn)接口;匿名類是內(nèi)部類的一種;內(nèi)部類通過各種方式可以在包含它的類的外部被訪問到;內(nèi)部類被定義在塊中時,只能訪問包含它的塊的final類型變量。故選擇D。
68.C
此題考察考生對類GridBagLayout、及類GridBagConstraints的掌握情況,請考生查閱API文檔。
69.B、C
此題考察考生對事件處理的理解。D選項是錯的,因為控件可以監(jiān)聽自己的事件。另外,當實現(xiàn)一個接口時,必須實現(xiàn)它內(nèi)部的所有的方法,所以E選項也是錯的。
70.A
命令行參數(shù)是緊跟在類名后面的。所以本題中參數(shù)由“cat”提供。
71.E
在完全封裝類中,一般的定義方式是將所有的成員變量定義為“private”,而將訪問這些變量的方法定義為非“private”類型,這樣可以在類的外部間接地訪問這些變量。所以E選項是最符合這個意思的。
72.B
此題考察“Collection API”的一些知識。實現(xiàn)接口“Set”的類內(nèi)部所存儲的對象是沒有順序,但是允許重復(fù)的。另請注意其它幾個接口的特征。
73.A、B、D、E
當新線程被創(chuàng)建時,只是使它變?yōu)榭蛇\行狀態(tài)而已,并不能使當前線程停止執(zhí)行。當調(diào)用read()方法時,它與輸入輸出打交道,可能造成線程的暫停執(zhí)行。
74.D、E
程序的執(zhí)行完畢是以用戶線程(user threads)的結(jié)束而標志結(jié)束的,與超級線程(daemon threads)無關(guān)。所以D選項是對的。E選項說明的是當不同線程對相同數(shù)據(jù)進行訪問時,可能造成數(shù)據(jù)毀損。
75.A、B
76.B、D
程序的代碼是無法對垃圾回收進行精確控制的,程序代碼與垃圾回收是相互獨立的系統(tǒng),并不互相影響。答案D告訴我們程序員可以使一個本地變量失去任何意義,例如給本地變量賦值為“null”;