1.Which statement about the garbage collection mechanism are true?
A. Garbage collection require additional programe code in cases where multiple threads are running.
B. The programmer can indicate that a reference through a local variable is no longer of interest.
C. The programmer has a mechanism that explicity and immediately frees the memory used by Java objects.
D. The garbage collection mechanism can free the memory used by Java Object at explection time.
E. The garbage collection system never reclaims memory from objects while are still accessible to running user threads.
2. Give the following method:
1) public void method( ){
2) String a,b;
3) a=new String(“hello world”);
4) b=new String(“game over”);
5) System.out.println(a+b+”ok”);
6) a=null;
7) a=b;
8) System.out.println(a);
9) }
In the absence of compiler optimization, which is the earliest point the object a refered is definitely elibile to be garbage collection.
A. before line 3
B.before line 5
C. before line 6
D.before line 7
E. Before line 9
3. In the class java.awt.AWTEvent,which is the parent class upon which jdk1.1 awt events are based there is a method called getID which phrase accurately describes the return value of this method?
A. It is a reference to the object directly affected by the cause of the event.
B. It is an indication of the nature of the cause of the event.
C. It is an indication of the position of the mouse when it caused the event.
D. In the case of a mouse click, it is an indication of the text under the mouse at the time of the event.
E. It tells the state of certain keys on the keybord at the time of the event.
F. It is an indication of the time at which the event occurred.
4. Which statement about listener is true?
A. Most component allow multiple listeners to be added.
B. If multiple listener be add to a single component, the event only affected one listener.
C. Component don?t allow multiple listeners to be add.
D. The listener mechanism allows you to call an addXxxxListener method as many times as is needed, specifying as many different listeners as your design require.
5.Give the following code:
public class Example{
public static void main(String args[] ){
int l=0;
do{
System.out.println(“Doing it for l is:”+l);
}while(--l>0)
System.out.println(“Finish”);
}
}
Which well be output:
A. Doing it for l is 3
B. Doing it for l is 1
C. Doing it for l is 2
D. Doing it for l is 0
E. Doing it for l is ?C1
F. Finish
見1-5題及詳細分析:
1。B、E JAVA的垃圾回收機制是通過一個后臺系統(tǒng)級線程對內(nèi)存分配情況進行跟蹤實現(xiàn)的,對程序員來說是透明的,程序員沒有任何方式使無用內(nèi)存顯示的、立即的被釋放。而且它是在程序運行期間發(fā)生的。
答案B告訴我們程序員可以使一個本地變量失去任何意義,例如給本地變量賦值為“null”;答案E告訴我們在程序運行期間不可能完全釋放內(nèi)存。
2。D第6行將null賦值給a以后,a以前保存的引用所指向的內(nèi)存空間就失去了作用,它可能被釋放。所以對象a可能最早被垃圾回收是在第7行以前,故選擇D選項。
3。B請查閱JAVA類庫。getID方法的返回值是“event type”。在認證考試中,總會有類似的書本以外的知識,這只能靠多實踐來增長知識了。
4。A、D控件可以同時使用多個“addXxxxListener”方法加入多個監(jiān)聽器。并且當(dāng)多個監(jiān)聽器加入到同一控件中時,事件可以響應(yīng)多個監(jiān)聽器,響應(yīng)是沒有固定順序的。
5。D、F本題主要考察考生對流程控制的掌握情況。這是當(dāng)型循環(huán),條件為真執(zhí)行,條件為假則退出。循環(huán)體至少執(zhí)行一次,故會輸出D。循環(huán)體以外的語句總會被執(zhí)行,故輸出F。
6. Give the code fragment:
1) switch(x){
2) case 1:System.out.println(“Test 1”);break;
3) case 2:
4) case 3:System.out.println(“Test 2”);break;
5) default:System.out.println(“end”);
6) }
which value of x would cause “Test 2” to the output:
A. 1
B. 2
C. 3
D. default
7. Give incompleted method:
1)
2) { if(unsafe()){//do something…}
3) else if(safe()){//do the other…}
4) }
The method unsafe() well throe an IOException, which completes the method of declaration when added at line one?
A. public IOException methodName()
B. public void methodName()
C. public void methodName() throw IOException
D. public void methodName() throws IOException
E. public void methodName() throws Exception
8. Give the code fragment:
if(x>4){
System.out.println(“Test 1”);}
else if (x>9){
System.out.println(“Test 2”);}
else {
System.out.println(“Test 3”);}
Which range of value x would produce of output “Test 2”?
A. x<4
B. x>4
C. x>9
D. None
9. Give the following method:
public void example(){
try{
unsafe();
System.out.println(“Test1”);
}catch(SafeException e){System.out.println(“Test 2”);
}finally{System.out.println(“Test 3”);}
System.out.println(“Test 4”);
Which will display if method unsafe () run normally?
A. Test 1
B. Test 2
C. Test 3
D. Test 4
10. Which method you define as the starting point of new thread in a class from which new the thread can be excution?
A. public void start()
B. public void run()
C. public void int()
D. public static void main(String args[])
E. public void runnable()
6-10答案:
6。B.C在開關(guān)語句中,標號總是不被當(dāng)做語句的一部分,標號的作用就是做為條件判斷而已,一旦匹配成功,就執(zhí)行其后的語句,一直遭遇break語句為止。(包括default語句在內(nèi))
7。D、F IOException異常類是Exception的子類。根據(jù)多態(tài)性的定義,IOException對象也可以被認為是Exception類型。還要注意在方法聲明中拋出異常應(yīng)用關(guān)鍵字“throws”。
8。D只有兩種情況:大于4時輸出“Test1”,小于等于4時輸出“Test3”。
9。A、C、D在正常情況下,打印Test1、Test3、Test4;在產(chǎn)生可捕獲異常時打印Test2、Test3、Test4;在產(chǎn)生不可捕獲異常時,打印Test3,然后終止程序。注意finally后面的語句總是被執(zhí)行。
10。B線程的執(zhí)行是從方法“run( )”開始的,該方法是由系統(tǒng)調(diào)用的。程序員手工調(diào)用方法start(),使線程變?yōu)榭蛇\行狀態(tài)。
11.Given the following class definition:
class A{
protected int i;
A(int i){
this.i=i;
}
}
which of the following would be a valid inner class for this class?
Select all valid answers:
A. class B{
}
B. class B extends A{
}
C. class B extends A{
B(){System.out.println(“i=”+i);}
}
D. class B{
class A{}
}
E. class A{}
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?
A. synchronized
B. abstract
C. final
D. static
E. public
13. The following code is entire contents of a file called Example.java,causes precisely one error during compilation:
1) class SubClass extends BaseClass{
2) }
3) class BaseClass(){
4) String str;
5) public BaseClass(){
6) System.out.println(“ok”);}
7) public BaseClass(String s){
8) str=s;}}
9) public class Example{
10) public void method(){
11) SubClass s=new SubClass(“hello”);
12) BaseClass b=new BaseClass(“world”);
13) }
14) }
Which line would be cause the error?
A. 9 B. 10 C. 11 D.12
14. Which statement is correctly declare a variable a which is suitable for refering to an array of 50 string empty object?
A. String [] a
B. String a[]
C. char a[][]
D. String a[50]
F. Object a[50]
15. Give the following java source fragement:
//point x
public class Interesting{
//do something
}
Which statement is correctly Java syntax at point x?
A. import java.awt.*;
B.package mypackage
C. static int PI=3.14
D. public class MyClass{//do other thing…} E. class MyClass{//do something…}
11-15答案:
11。A此題考查內(nèi)部類及關(guān)鍵字“super”的用法。內(nèi)部類不能與外部類同名。另外,當(dāng)B繼承A?xí)r,A中的構(gòu)造函數(shù)是帶參數(shù)的,B中缺省構(gòu)造函數(shù)的函數(shù)體為空;而JAVA編譯器會為空構(gòu)造函數(shù)體自動添加語句“super();”調(diào)用父類構(gòu)造函數(shù),更進一步是調(diào)用父類的參數(shù)為空的構(gòu)造函數(shù)。而父類中沒有參數(shù)為空的構(gòu)造函數(shù)。
12。A此關(guān)鍵字可以在兩個線程同時試圖訪問某一數(shù)據(jù)時避免數(shù)據(jù)毀損。
13。C當(dāng)一個類中未顯式定義構(gòu)造函數(shù)時,缺省的構(gòu)造函數(shù)是以類名為函數(shù)名,參數(shù)為空,函數(shù)體為空。雖然父類中的某一構(gòu)造函數(shù)有字符串參數(shù)s,但是子類繼承父類時并不繼承構(gòu)造函數(shù),所以它只能使用缺省構(gòu)造函數(shù)。故在第11行出錯。
14。A、B注意,題中問的是如何正確聲明一個一維數(shù)組,并非實例化或者初始化數(shù)組
15。A、E X處可以是一個輸入,包的定義,類的定義。由于常量或變量的聲明只能在類中或方法中,故不能選擇C;由于在一個文件中只能有一個public類,故不能選擇D。
16. Give this class outline:
class Example{
private int x;
//rest of class body…
}
Assuming that x invoked by the code java Example, which statement can made x be directly accessible in main() method of Example.java?
A. Change private int x to public int x
B. change private int x to static int x
C. Change private int x to protected int x
D. change private int x to final int x
17. the piece of preliminary analsis work describes a class that will be used frequently in many unrelated parts of a project
“The polygon object is a drawable, A polygon has vertex information stored in a vector, a color, length and width.”
Which Data type would be used?
A. Vector
B. int
C. String
D. Color
E. Date
18. A class design requires that a member variable should be accessible only by same package, which modifer word should be used?
A. protected
B. public
C. no modifer
D. private
19.Which declares for native method in a java class corrected?
A. public native void method(){}
B. public native void method();
C. public native method();
D. public void method(){native;}
E. public void native method();
20. Which modifer should be applied to a declaration of a class member variable for the value of variable to remain constant after the creation of the object?
16-20答案:
16。B
靜態(tài)方法除了自己的參數(shù)外只能直接訪問靜態(tài)成員。訪問非靜態(tài)成員,必須先實例化本類的一個實例,再用實例名點取。
17。A、B、D
polygon的頂點信息存放在Vector類型的對象內(nèi)部,color定義為Color,length和width定義為int。
注意,這是考試中常見的題型。
18。C
此題考點是高級訪問控制。請考生查閱高級訪問控制說明表格。
19。B
native關(guān)鍵字指明是對本地方法的調(diào)用,在JAVA中是只能訪問但不能寫的方法,它的位置在訪問權(quán)限修飾語的后面及返回值的前面。
20。final
定義常量的方法是在變量定義前加final關(guān)鍵字。
21. Which is the main() method return of a application?
A. String
B. byte
C. char
D. void
22. Which is corrected argument of main() method of application?
A. String args
B. String ar[]
C. Char args[][]
D. StringBuffer arg[]
23. “The Employee object is a person, An Employee has appointment store in a vector, a hire date and a number of dependent”
short answer: use shortest statement declare a class of Employee.
24. Give the following class defination inseparate source files:
public class Example{
public Example(){//do something}
protected Example(int i){//do something}
protected void method(){//do something}
}
public class Hello extends Example{//member method and member variable}
Which methods are corrected added to the class Hello?
A. public void Example(){}
B. public void method(){}
C. protected void method(){}
D. private void method(){}
25. Float s=new Float(0.9F);
Float t=new Float(0.9F);
Double u=new Double(0.9);
Which expression?s result is true?
A. s==t
B. s.equals(t)
C. s==u
D. t.equals(u)
21-15答案:
21。D
main()方法沒有返回值,所以必須用void修飾。main()方法的返回值不能任意修改。
22。B
main()方法的參數(shù)是字符串?dāng)?shù)組,參數(shù)名可以任意定義。
23。public class Employee extends Person
這也是真實考試中常見的一種題型。要注意題目敘述中“is a”表示 “extends”的含義。
24。A、B、C
考察的知識點是方法覆蓋,其中要注意的是方法覆蓋時,子類方法的訪問權(quán)限不能小于父類方法的訪問權(quán)限。另外,選項A并不是父類構(gòu)造函數(shù),它是子類中的新方法。
25。A、B
考察“==”及方法“equals()”的用法。注意以下幾點區(qū)別:
1) 引用類型比較引用;基本類型比較值。
2) equals()方法只能比較引用類型,“==”可比較引用及基本類型。
3) 當(dāng)用equals()方法進行比較時,對類File、String、Date及封裝類(Wrapper Class)來說,是比較類型及內(nèi)容。
4) 用“==”進行比較時,符號兩邊的數(shù)據(jù)類型必須一致(可相互轉(zhuǎn)換的基本類型除外),否則編譯出錯。
26. Give following class:
class AClass{
private long val;
public AClass(long v){val=v;}
public static void main(String args[]){
AClass x=new AClass(10L);
AClass y=new AClass(10L);
AClass z=y;
long a=10L;
int b=10;
}
}
Which expression result is true?
A. a==b;
B. a==x;
C. y==z;
D. x==y;
E. a==10.0;
27. A socket object has been created and connected to a standard internet service on a remote network server. Which construction give the most suitable means for reading ASCII data online at a time from the socket?
A. InputStream in=s.getInputStream();
B. DataInputStream in=new DataInputstream(s.getInputStream());
C. ByteArrayInputStream in = new ByteArrayInputStream (s.getInputStream());
D. BufferedReader in=new BufferedReader (new InputStreamReader (s.getInputStream()));
E. BufferedReader in=new BufferedReader (new InputStreamReader (s.getInputStream()),”8859-1”);
28. String s=”Example String”;
Which operation is legal?
A. s>>>=3;
B. int i=s.length();
C. s[3]=”x”;
D. String short_s=s.trim();
E. String t=”root”+s;
29. What happens when you try to compile and run the following program?
class Mystery{
String s;
public static void main(String[] args){
Mystery m=new Mystery();
m.go();
}
void Mystery(){
s=”constructor”;
}
void go(){
System.out.println(s);
}
}
A. this code will not compile
B. this code compliles but throws an exception at runtime
C. this code runs but nothing appears in the standard output
D. this code runs and “constructor” in the standard output
E. this code runs and writes ”null” in the standard output
30. What use to position a Button in a Frame ,only width of Button is affected by the Frame size, which Layout Button well be set ?
A. FlowLayout;
B. GridLayout;
C. North of BorderLayout
D. South of BorderLayout
E. East or West of BorderLayout
31. What use to position a Button in a Frame, size of Button is not affected by the Frame size, which Layout Button will be set?
A. FlowLayout;
B. GridLayout;
C. North of BorderLayout
D. South of BorderLayout
E. East or West of BorderLayout
32. An AWT GUI under exposure condition, which one or more method well be invoke when it redraw?
A. paint();
B. update();
C. repaint();
D. drawing();
33. Select valid identifier of Java:
A. userName
B. %passwd
C. 3d_game
D. $charge E. this
34. Which are Java keyword?
A. goto
B. null
C. FALSE
D. native
E. const
35. Run a corrected class: java ?Ccs AClass a b c
Which statement is true?
A. args[0]=”-cs”;
B. args[1]=”a b c”;
C. args[0]=”java”;
D. args[0]=”a”; E. args[1]=?b?
36. Give the following java class:
public class Example{
static int x[]=new int[15];
public static void main(String args[]){
System.out.println(x[5]);
}
}
Which statement is corrected?
A. When compile, some error will occur.
B. When run, some error will occur.
C. Output is zero.
D. Output is null.
37. Give the following java class:
public class Example{
public static void main(String args[]){
static int x[] = new int[15];
System.out.println(x[5]);
}
}
Which statement is corrected?
A. When compile, some error will occur.
B. When run, some error will occur.
C. Output is zero.
D. Output is null.
38. Short answer:
The decimal value of i is 12, the octal i value is:
39. Short answer:
The decimal value of i is 7, the hexadecimal i value is:
40. Which is the range of char?
A. 27~27-1
B. 0~216-1
C. 0~216
D. 0~28
41. Which is the range of int type?
A. -216~216-1
B.- 231~231-1
C. -232~232-1
D. -264~264-1
42. Give the following class:
public class Example{
String str=new String(“good”);
char ch[]={
public static void main(String args[]){
Example ex=new Example();
ex.change(ex.str,ex.ch);
System.out.println(ex.str+”and”+ex.ch);
}
public void change(String str,char ch[]){
str=”test ok”;ch[0]=?g?
}
}
Which is the output:
A. good and abc
B. good and gbc
C. test ok and abc
D. test ok and gbc
43. Which code fragments would correctly identify the number of arguments passed via command line to a Java application, exclude the name of the class that is being invoke.
A. int count = args.length;
B. int count = args.length-1;
C. int count=0; while(args[count]!=null) count++;
D. int count=0;while (!(args[count].equals(“”))) count++;
44. FilterOutputStream is the parent class for BufferedOutputStream, DataOutputStream and PrintStream. Which classes are valid argument for the constructor of a FilterOutputStream?
A. InputStream
B. OutputStream
C. File
D. RandomAccessFile
E. StreamTokenizer
45. Given a TextArea using a proportional pitch font and constructed like this:
TextArea t=new TextArea(“12345”,5,5);
Which statement is true?
A. The displayed width shows exactly five characters one each line unless otherwise constrained
B. The displayed height is five lines unless otherwise constrained
C. The maximum number of characters in a line will be five
D. The user will be able to edit the character string
E. The displayed string can use multiple fonts
46. Given a List using a proportional pitch font and constructed like this:
List l=new List(5,true);
Which statement is true?
A. The displayed item exactly five lines unless otherwise constrained
B. The displayed item is five lines init, but can displayed more than five Item by scroll
C. The maximum number of item in a list will be five.
D. The list is multiple mode
47. Given this skeleton of a class currently under construction:
public class Example{
int x,y,z;
public Example (int a, int b) {
//lots of complex computation
x=a; y=b;
}
public Example(int a, int b, int c){
// do everything the same as single argument
// version of constructor
// including assignment x=a, y=b, z=c
z=c;
}
}
What is the most concise way to code the “do everything…” part of the constructor taking two arguments?
Short answer:
48. Which correctly create a two dimensional array of integers?
A. int a[][] = new int[][];
B. int a[10][10] = new int[][];
C. int a[][] = new int[10][10];
D. int [][]a = new int[10][10];
E. int []a[] = new int[10][10];
49. Which are correct class declarations? Assume in each case that the text constitutes the entire contents of a file called Fred.java?
A. public class Fred{
public int x = 0;
public Fred (int x){
this.x=x;
}
}
B. public class fred{
public int x = 0;
public Fred (int x){
this.x=x;
}
}
C. public class Fred extends MyBaseClass, MyOtherBaseClass{
public int x = 0;
public Fred(int xval){
x=xval;
}
}
D. protected class Fred{
private int x = 0;
private Fred (int xval){
x=xval;
}
}
E. import java.awt.*;
public class Fred extends Object{
int x;
private Fred(int xval){
x = xval;
}
}
50. A class design requires that a particular member variable must be accessible for direct access by any subclasses of this class. but otherwise not by classes which are not members of the same package. What should be done to achieve this?
A. The variable should be marked public
B. The variable should be marked private
C. The variable should be marked protected
D. The variable should have no special access modifier
E. The variable should be marked private and an accessor method provided
答案及詳細分析:
26。A、C、E
考察的知識點是比較基本類型與對象類型的不同之處,基本類型進行的是值比較,而對象類型進行的是地址比較,也就是對指向它們內(nèi)存地址的指針進行比較。
27。E
在程序中實現(xiàn)字節(jié)與字符轉(zhuǎn)換時,采用規(guī)范“ISO8859-1”是最適宜的方式。
28。B、D、E
移位操作只對整型有效,故不能選A;String類型并非數(shù)組,故不能用C所示方法取其中的某一位;B中的length方法返回字符串長度;D中trim方法返回字符串去掉其前后的空格后的新字符串;字符串可以用“+”進行合并。
29。E
回答本題時要細心閱讀程序,注意“void Mistery(){}”并非構(gòu)造函數(shù),因為構(gòu)造函數(shù)是沒有返回值時,它只是與類名一致的方法名而已。注意到這一點,此題就沒有什么難度了。
30。C、D
考察對布局管理器知識的掌握情況。BorderLayout的特性是當(dāng)容器的尺寸改變時,North、South、West、East位置控件的較窄邊長度不變,較長邊長度變化。但控件的相對位置不變。
31。A
FlowLayout的特性是其中的控件大小不隨著容器尺寸的變化而變化,但控件的相對位置會有所改變。
32。A(多選)
請注意,此題雖然是多選題,但正確答案只有一個。不管在什么情況下,圖形要進行重繪,最終總會調(diào)用paint()方法,而且也只有paint()方法總會被調(diào)用。
33。A、D
Java中的標識符是以字符開頭,字符包括字母、下劃線“_”、美圓符“$”。不能以數(shù)字開頭,也不能是Java關(guān)鍵字。
34。A、B、D、E
注意:goto、const是Java關(guān)鍵字,但是不使用。
35。D
cs是運行時可選擇的java命令的參數(shù),類名后才是由用戶指定的傳入程序中的實參,并且參數(shù)是字符串類型,故E也是不正確的。
36。C
數(shù)組是引用類型,它的元素相當(dāng)于類的成員變量,而成員變量是可以被隱式初始化的,所以數(shù)組的元素也可以被隱式初始化,int類型被隱式初始化為0,所以選擇C。
37。A
自動變量不能被static修飾,如果將static關(guān)鍵字去掉,答案選擇C。
38。014
將十進制化成八進制后在數(shù)字前加“0”。
39。0x7
十六進制數(shù)用在數(shù)字前加“0x”表示。
40。B
字符類型是用16位UniCode表示的。
41。B
整型數(shù)的取值范圍是- 2n~2n-1,n表示各種類型的表示位數(shù)。
42。B
JAVA中的參數(shù)傳遞全是值傳遞,所不同的是,對于引用類型來說,變量內(nèi)部存放的是對象內(nèi)存空間的引用,所以引用類型在進行參數(shù)傳遞時,是將引用拷貝給形式參數(shù)。所以在方法中絕不可能改變主調(diào)方法中引用變量的引用,但是可能改變主調(diào)方法中引用變量的某一屬性(就象對ch[0]的改變一樣)。
43。A
注意main()方法的參數(shù)數(shù)組是在程序運行時由系統(tǒng)創(chuàng)建的,大小已經(jīng)固定了。選項C、D引用args[count]可能會導(dǎo)致數(shù)組指針越界異常。
44。B
請查閱類結(jié)構(gòu),并注意他們的繼承關(guān)系。這主要考查流鏈知識點。
45。B
控件TextArea如題中的構(gòu)造方法的后兩個參數(shù)分別表示行、列。注意題中的關(guān)鍵詞語“prorortional pitch”,所以不一定是5列字,但一定是5行。
46。B
“5”表示可以選擇的項目數(shù)顯示為5行,但可以拖動滑塊觀察其它選項。“true”表示可以多選。
47。this(a,b);
注意教材中提到使用this方法可以簡化構(gòu)造函數(shù)的編寫。此時它必須放在構(gòu)造函數(shù)的第一句。
48。C、D、E
JAVA語言中聲明數(shù)組時,方括號與變量的位置關(guān)系非常靈活。
49。A、E
Java中大小寫敏感,注意文件名是Fred.java,故B錯誤;Java中不支持多繼承,故C錯誤;Java中與文件名相同的類名的訪問權(quán)限一定是public,故D錯誤。
50。C
請查閱關(guān)于訪問權(quán)限的表格說明。
51. Which correctly create an array of five empty Strings?
A. String a[] = new String[5];
for (int i=0;i<5;a[i++]=””);
B. String a []={“”,””,””,””,””};
C. String a[5];
D. String [5] a;
E. String [] a = new String[5];
for (int i = 0 ;i<5;a[i++] = null);
52. Which cannot be added to a Container?
A. an Applet
B. a Component
C. a Container
D. a MenuComponent
E. a panel
53. Which is the return value of Event listener?s method?
A. String B. AWTEvent C. void D. int
54. If we implements MouseListener, which is corrected argument of its method? (short answer)
55. Use the operator “>>” and “>>>”. Which statement is true?
A. 1010 0000 0000 0000 0000 0000 0000 0000 >> 4 give
0000 1010 0000 0000 0000 0000 0000 0000
B. 1010 0000 0000 0000 0000 0000 0000 0000 >> 4 give
1111 1010 0000 0000 0000 0000 0000 0000
C. 1010 0000 0000 0000 0000 0000 0000 0000 >>> 4 give
0000 1010 0000 0000 0000 0000 0000 0000
D. 1010 0000 0000 0000 0000 0000 0000 0000 >>> 4 give
1111 1010 0000 0000 0000 0000 0000 0000
56. Give following fragment.
Outer: for(int i=0; i<3; i++)
inner:for(int j=0;j<3;j++){
If(j>1)break outer;
System.out.println(j+”and”+i);
}
Which will be output?
A. 0 and 0 B. 0 and 1 C. 0 and 2 D. 0 and 3
E. 1 and 0 F. 1 and 1 G. 1 and 2 H. 1 and 3
I. 2 and 0 J. 2 and 1 K. 2 and 2 L. 2 and 3
57. Examine the following code which includes an inner class:
public final class Test4 implements A{
class Inner{
void test(){
if (Test4.this.flag);{
sample();
}
}
private boolean flag=false;
}
public void sample(){
System.out.println(“Sample”);
}
public Test4(){
(new Inner()).test();
}
public static void main(String args[]){
new Test4();
}
}
What is the result:
A.Print out “Sample”
B.Program produces no output but termiantes correctly.
C. Program does not terminate.
D.The program will not compile
58. What is written to the standard output given the following statement:
System.out.println(4|7);
Select the right answer:
A.4
B.5
C.6
D.7
E.0
59. Look the inheritance relation:
person
|
----------------
| |
man woman
In a source of java have the following line:
person p=new man();
What statement are corrected?
A. The expression is illegal.
B. Compile corrected but running wrong.
C. The expression is legal.
D. Will construct a person?s object.
60. Look the inheritance relation:
person
|
----------------
| |
man woman
In a source of java have the following line:
woman w=new man():
What statement are corrected?
A. The expression is illegal.
B. Compile corrected but running wrong.
C. The expression is legal.
D. Will construct a woman object.
61. Which can NOT be used in declaring or declaring and initializing an automatic (method local) variable?
A. final
B. static
C. expressions
D. Constants of non-primitive type
E. initialized arrays (such as “ {“Hello”,”Good bye”}”).
62. Given the following incomplete method:
1) public void method(){
2)
3) if (someTestFails()){
4)
5) }
6)
7) }
You want to make this method throw an IOException if,and only if,the method someTestFails() returns a value of true.
Which changes achieve this?
A. Add at line 2:IOException e;
B. Add at line 4:throw e;
C. Add at line 4:throw new IOException();
D. Add at line 6:throw new IOException();
E. Modify the method declaration to indicate that an object of type Exception might be thrown.
63. Given the following definition:
String s = null;
Which code fragments cause an object of type NullPointerException to be thrown?
A. if((s!=null)&(s.length()>0))
B. if((s!=null)&&(s.length()>0))
C. if((s==null)|(s.length()==0))
D. if((s==null)||(s.length()==0))
64. The following is a program
1) class Exsuper{
2) String name;
3) String nick_name;
4)
5) public ExSuper(String s,String t){
6) name = s;
7) nick_name = t;
8) }
9)
10) public string toString(){
11) return name;
12) }
13) }
14)
15) public class Example extends ExSuper{
16)
17) public Example(String s,String t){
18) super(s,t);
19) }
20)
21) public String to String(){
22) return name +”a.k.a”+nick_name;
23) }
24)
25) public static void main(String args[]){
26) ExSuper a = new ExSuper(“First”,”1st”);
27) ExSuper b = new Example(“Second”,”2nd”);
28)
29) System.out.println(“a is”+a.toString());
30) System.out.println(“b is”+b.toString());
31) }
32) }
What happens when the user attempts to compile and run this program?
A. A Compiler error occurs at line 21
B. An object of type ClassCastException is thrown at line 27
C.The following output:
a is First
b is second
D. The following output:
a is First
b is Secong a.k.a 2nd
F. The following output:
a is First a.k.a 1st
b is Second a.k.a 2nd
65. Which statements are true about Listeners?
A. At most one listener can be added to any simple Component.
B. The return value from a listener is used to control the invocation of other listener
C. If multiple listeners are added to a single component, they must all be made friends to each other
D. If multiple listeners are added to single component, the order of invocation of the listener is not specified.
E. In the AWT, listener methods generally take an argument, which is an instance of some subclass of java.awt.AWTEvent class.
答案及詳細分析:
51。A、B
注意,每個對象變量在未初始化前都為“null”,并不為“空”。當(dāng)為“空”時,它已經(jīng)被分配具體內(nèi)存空間了,與“null”有本質(zhì)的區(qū)別。
52。D
菜單控件只能添加到叫做菜單容器的特殊對象中,而且布局管理器對菜單控件不起任何作用。
53。C
事件監(jiān)聽器方法就是句柄方法,所有句柄方法的訪問權(quán)限都是public,返回值類型都是void。
54。MouseEvent
此題是考試中常見的題型。一般來說,句柄方法的參數(shù)類型與監(jiān)聽器類型是匹配的,只有監(jiān)聽器MouseMotionListener的句柄方法的參數(shù)類型是MouseEvent,與相應(yīng)監(jiān)聽器類型名稱不匹配。
55。B、C
“>>” 是帶符號右移,高位是“1”則補“1”,否則補“0”;“>>>”是無符號右移,又叫補零右移,不論高位是什么,都是補“0”。
56。A、E
注意標號的使用。另外,break表示跳出本語句塊的執(zhí)行,continue繼續(xù)本塊的執(zhí)行。
57。A
回答此題時,要仔細閱讀程序,注意到語句“if(Test4.this.flag);”有一分號,這是沒有執(zhí)行語句的條件語句,所以“sample()”方法總是被調(diào)用。
58。D
“|”是按位或運算符,先將4和7轉(zhuǎn)為二進制數(shù)。轉(zhuǎn)換后就是計算“100|111”,所以得到結(jié)果是“111”,轉(zhuǎn)為十進制整形數(shù)是7。此題提醒考生注意,要熟悉各種運算符號的含義。
59。C
這是多態(tài)性的定義方式,p是父類引用指向子類對象。此時,編譯器認為p是一個person,而不是man ,所以p只能實現(xiàn)父類的功能。但是當(dāng)p調(diào)用被覆蓋方法時,是指向子類中的該方法。
60.A
多態(tài)性的定義允許父類引用指向子類對象,但是不允許兩個平等的子類有這樣的操作。所以該表達式是不合法的。
61.B
自動變量前不能用“static”修飾。
以下定義都是允許的:
final Date d = new Date();
String [] s = {“Hello”,”abc”};
int i = x+4;
所以只有B選項是正確。
62.C、E
所有自定義異常,在方法體中拋出了,就必須在方法聲明中拋出。所以除了C選項外,E也必須入選。
63.A、C
邏輯運算符“&&”、“||”,在運算中有“短路”行為:例如 A&&B,如果A的值為false,則直接將整個表達式的值置為false,對B的值不加考察。而運算符“&”、“|”就沒有這種行為。所以在選項A、C中,“s.length()”會導(dǎo)致拋出空指針異常。
64.D
源程序的第27行,是多態(tài)性的定義。對象b調(diào)用被覆蓋方法時是調(diào)用子類中的該方法。
65.D、E
一個控件可以注冊多個監(jiān)聽器,并且事件的響應(yīng)沒有特定的順序。句柄方法的參數(shù)是類AWTEvent類的子類。
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)聽自己的事件。另外,當(dāng)實現(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
當(dāng)新線程被創(chuàng)建時,只是使它變?yōu)榭蛇\行狀態(tài)而已,并不能使當(dāng)前線程停止執(zhí)行。當(dāng)調(diào)用read()方法時,它與輸入輸出打交道,可能造成線程的暫停執(zhí)行。
74.D、E
程序的執(zhí)行完畢是以用戶線程(user threads)的結(jié)束而標志結(jié)束的,與超級線程(daemon threads)無關(guān)。所以D選項是對的。E選項說明的是當(dāng)不同線程對相同數(shù)據(jù)進行訪問時,可能造成數(shù)據(jù)毀損。
75.A、B
76.B、D
程序的代碼是無法對垃圾回收進行精確控制的,程序代碼與垃圾回收是相互獨立的系統(tǒng),并不互相影響。答案D告訴我們程序員可以使一個本地變量失去任何意義,例如給本地變量賦值為“null”;