當前位置:才華齋>計算機>java語言>

java程式設計師認證模擬試題及解析

java語言 閱讀(2.3W)

天將降大任於是人也,必先苦其心志,勞其筋骨,餓其體膚,空乏其身,行拂亂其所為。以下是小編為大家搜尋整理的java程式設計師認證模擬試題解析,希望能給大家帶來幫助!更多精彩內容請及時關注我們應屆畢業生考試網!

java程式設計師認證模擬試題及解析

Java程式設計師認證模擬題及詳細分析(1)

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=nputStream();

B. DataInputStream in=new DataInputstream(nputStream());

C. ByteArrayInputStream in=new ByteArrayInputStream(nputStream());

D. BufferedReader in=new BufferedReader(new InputStreamReader(nputStream()));

E. BufferedReader in=new BufferedReader(new InputStreamReader(nputStream()),”8859-1”);

28. String s=”Example String”;

Which operation is legal?

A. s>>>=3;

B. int i=th();

C. s[3]=”x”;

D. String short_s=();

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();

();

}

void Mystery(){

s=”constructor”;

}

void go(){

tln(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[]){

tln(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];

tln(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();

ge(,);

tln( ”and” );

}

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 = th;

B. int count = th-1;

C. int count=0; while(args[count]!=null)

count ;

D. int count=0;while

(!(args[count]ls(“”))) 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 ?

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 .*;

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

考察的知識點是比較基本型別與物件型別的不同之處,基本型別進行的是值比較,而物件型別進行的是地址比較,也就是對指向它們記憶體地址的指標進行比較。

27。E

在程式中實現位元組與字元轉換時,採用規範“ISO8859-1”是最適宜的方式。

28。B、D、E

移位操作只對整型有效,故不能選A;String型別並非陣列,故不能用C所示方法取其中的某一位;B中的length方法返回字串長度;D中trim方法返回字串去掉其前後的空格後的新字串;字串可以用“ ”進行合併。

29。E

回答本題時要細心閱讀程式,注意“void Mistery(){}”並非建構函式,因為建構函式是沒有返回值時,它只是與類名一致的方法名而已。注意到這一點,此題就沒有什麼難度了。

30。C、D

考察對佈局管理器知識的掌握情況。BorderLayout的特性是當容器的尺寸改變時,North、South、West、East位置控制元件的較窄邊長度不變,較長邊長度變化。但控制元件的相對位置不變。

31。A

FlowLayout的特性是其中的控制元件大小不隨著容器尺寸的變化而變化,但控制元件的相對位置會有所改變。

32。A(多選)

請注意,此題雖然是多選題,但正確答案只有一個。不管在什麼情況下,圖形要進行重繪,最終總會呼叫paint()方法,而且也只有paint()方法總會被呼叫。

33。A、D

Java中的識別符號是以字元開頭,字元包括字母、下劃線“_”、美圓符“$”。不能以數字開頭,也不能是Java關鍵字。

34。A、B、D、E

注意:goto、const是Java關鍵字,但是不使用。

35。D

cs是執行時可選擇的java命令的引數,類名後才是由使用者指定的傳入程式中的實參,並且引數是字串型別,故E也是不正確的。

36。C

陣列是引用型別,它的元素相當於類的成員變數,而成員變數是可以被隱式初始化的,所以陣列的元素也可以被隱式初始化,int型別被隱式初始化為0,所以選擇C。

37。A

自動變數不能被static修飾,如果將static關鍵字去掉,答案選擇C。

38。014

將十進位制化成八進位制後在數字前加“0”。

39。0x7

十六進位制數用在數字前加“0x”表示。

40。B

字元型別是用16位UniCode表示的。

41。B

整型數的取值範圍是- 2n~2n-1,n表示各種型別的表示位數。

42。B

JAVA中的引數傳遞全是值傳遞,所不同的是,對於引用型別來說,變數內部存放的是物件記憶體空間的引用,所以引用型別在進行引數傳遞時,是將引用拷貝給形式引數。所以在方法中絕不可能改變主調方法中引用變數的引用,但是可能改變主調方法中引用變數的某一屬性(就象對ch[0]的'改變一樣)。

43。A

注意main()方法的引數陣列是在程式執行時由系統建立的,大小已經固定了。選項C、D引用args[count]可能會導致陣列指標越界異常。

44。B

請查閱類結構,並注意他們的繼承關係。這主要考查流鏈知識點。

45。B

控制元件TextArea如題中的構造方法的後兩個引數分別表示行、列。注意題中的關鍵詞語“prorortional pitch”,所以不一定是5列字,但一定是5行。

46。B

“5”表示可以選擇的專案數顯示為5行,但可以拖動滑塊觀察其它選項。“true”表示可以多選。

47。this(a,b);

注意教材中提到使用this方法可以簡化建構函式的編寫。此時它必須放在建構函式的第一句。

48。C、D、E

JAVA語言中宣告陣列時,方括號與變數的位置關係非常靈活。

49。A、E

Java中大小寫敏感,注意檔名是,故B錯誤;Java中不支援多繼承,故C錯誤;Java中與檔名相同的類名的訪問許可權一定是public,故D錯誤。

50。C

請查閱關於訪問許可權的表格說明。