亚洲精品成人18久久久久_日韩欧美色_江苏极品身材白嫩少妇自拍_曰本人做爰大片免费观看一老师_久草视频网_最近中文字幕MV高清在线视频

首頁 > 考試輔導 > 計算機考試 > JAVA認證 > JAVA認證試題集錦 > JAVA認證歷年真題:SCJP考試真題和解析[1]

JAVA認證歷年真題:SCJP考試真題和解析[1]

        例題1:

  choose the three valid identifiers from those listed below.

  a. idolikethelongnameclass

  b. $byte

  c. const

  d. _ok

  e. 3_case

  解答:a, b, d

  點評:java中的標示符必須是字母、美元符($)或下劃線(_)開頭。關鍵字與保留字不能作為標示符。選項c中的const是java的保留字,所以不能作標示符。選項e中的3_case以數字開頭,違反了java的規則。

  例題2:

  how can you force garbage collection of an object?

  a. garbage collection cannot be forced

  b. call system.gc().

  c. call system.gc(), passing in a reference to the object to be garbage collected.

  d. call runtime.gc().

  e. set all references to the object to new values(null, for example).

  解答:a

  點評:在java中垃圾收集是不能被強迫立即執行的。調用system.gc()或runtime.gc()靜態方法不能保證垃圾收集器的立即執行,因為,也許存在著更高優先級的線程。所以選項b、d不正確。選項c的錯誤在于,system.gc()方法是不接受參數的。選項e中的方法可以使對象在下次垃圾收集器運行時被收集。
 例題3:
 consider the following class:

  1. class test(int i) {

  2. void test(int i) {

  3. system.out.println(“i am an int.”);

  4. }

  5. void test(string s) {

  6. system.out.println(“i am a string.”);

  7. }
  
  8.
  
  9. public static void main(string args[]) {

  10. test t=new test();

  11. char ch=“y”;

  12. t.test(ch);

  13. }

  14. }

  which of the statements below is true?(choose one.)

  a. line 5 will not compile, because void methods cannot be overridden.

  b. line 12 will not compile, because there is no version of test() that rakes a char argument.

  c. the code will compile but will throw an exception at line 12.

  d. the code will compile and produce the following output: i am an int.

  e. the code will compile and produce the following output: i am a string.

  解答:d

  點評:在第12行,16位長的char型變量ch在編譯時會自動轉化為一個32位長的int型,并在運行時傳給void test(int i)方法。

例題4:

  which of the following lines of code will compile without error?

  a.
  int i=0;
  if (i) {
  system.out.println(“hi”);
  }

  b.
  boolean b=true;
  boolean b2=true;
  if(b==b2) {
  system.out.println(“so true”);
  }

  c.
  int i=1;
  int j=2;
  if(i==1|| j==2)
  system.out.println(“ok”);

  d.
  int i=1;
  int j=2;
  if (i==1 &| j==2)
  system.out.println(“ok”);

  解答:b, c

  點評:選項a錯,因為if語句后需要一個boolean類型的表達式。邏輯操作有^、&、| 和 &&、||,但是“&|”是非法的,所以選項d不正確。

  例題5:

  which two demonstrate a "has a" relationship? (choose two)

  a. public interface person { }

  public class employee extends person{ }

  b. public interface shape { }
  public interface rectandle extends shape { }

  c. public interface colorable { }
  public class shape implements colorable
  { }

  d. public class species{ }
  public class animal{private species species;}

  e. interface component{ }
  class container implements component{
  private component[] children;
  }

  解答:d, e

  點評: 在java中代碼重用有兩種可能的方式,即組合(“has a”關系)和繼承(“is a”關系)。“has a”關系是通過定義類的屬性的方式實現的;而“is a”關系是通過類繼承實現的。本例中選項a、b、c體現了“is a”關系;選項d、e體現了“has a”關系。

  例題6:

  which two statements are true for the class java.util.treeset? (choose two)
  
  a. the elements in the collection are ordered.

  b. the collection is guaranteed to be immutable.

  c. the elements in the collection are guaranteed to be unique.

  d. the elements in the collection are accessed using a unique key.
  e. the elements in the collection are guaranteed to be synchronized
  解答:a, c

  點評:treeset類實現了set接口。set的特點是其中的元素惟一,選項c正確。由于采用了樹形存儲方式,將元素有序地組織起來,所以選項a也正確。

例題7:

  true or false: readers have methods that can read and return floats and doubles.

  a. ture

  b. false

  解答:b

  點評: reader/writer只處理unicode字符的輸入輸出。float和double可以通過stream進行i/o.

  例題8:

  what does the following paint() method draw?

  1. public void paint(graphics g) {

  2. g.drawstring(“any question”, 10, 0);

  3. }

  a. the string “any question?”, with its top-left corner at 10,0

  b. a little squiggle coming down from the top of the component.

  解答:b

  點評:drawstring(string str, int x, int y)方法是使用當前的顏色和字符,將str的內容顯示出來,并且最左的字符的基線從(x,y)開始。在本題中,y=0,所以基線位于最頂端。我們只能看到下行字母的一部分,即字母‘y’、‘q’的下半部分。

  例題9:

  what happens when you try to compile and run the following application? choose all correct options.

  1. public class z {

  2. public static void main(string[] args) {

  3. new z();

  4. }

  5.

  6. z() {

  7. z alias1 = this;

  8. z alias2 = this;

  9. synchronized(alias1) {

  10. try {

  11. alias2.wait();

  12. system.out.println(“done waiting”);

  13. }

  14. catch (interruptedexception e) {

  15. system.out.println(“interr
  upted”);

  16. }

  17. catch (exception e) {
 
  18. system.out.println(“other exception”);

  19. }

  20. finally {

  21. system.out.println
  (“finally”);

  22. }

  23. }

  24. system.out.println(“all done”);

  25. }

  26. }

  a. the application compiles but doesn't print anything.

  b. the application compiles and print “done waiting”

  c. the application compiles and print “finally”

  d. the application compiles and print “all done”

  e. the application compiles and print “interrupted”

  解答:a

  點評:在java中,每一個對象都有鎖。任何時候,該鎖都至多由一個線程控制。由于alias1與alias2指向同一對象z,在執行第11行前,線程擁有對象z的鎖。在執行完第11行以后,該線程釋放了對象z的鎖,進入等待池。但此后沒有線程調用對象z的notify()和notifyall()方法,所以該進程一直處于等待狀態,沒有輸出。

例題10:

  which statement or statements are true about the code listed below? choose three.

  1. public class mytextarea extends textarea {

  2. public mytextarea(int nrows, int ncols) {

  3. enableevents(awtevent.text_
  event_mask);

  4. }

  5.

  6. public void processtextevent
  (textevent te) {

  7. system.out.println(“processing a text event.”);

  8. }

  9. }

  a. the source code must appear in a file called mytextarea.java

  b. between lines 2 and 3, a call should be made to super(nrows, ncols) so that the new component will have the correct size.

  c. at line 6, the return type of processtextevent() should be declared boolean, not void.

  d. between lines 7 and 8, the following code should appear: return true.

  e. between lines 7 and 8, the following code should appear: super.processtextevent(te).

  解答:a, b, e

  點評:由于類是public,所以文件名必須與之對應,選項a正確。如果不在2、3行之間加上super(nrows,ncols)的話,則會調用無參數構建器textarea(), 使nrows、ncols信息丟失,故選項b正確。在java2中,所有的事件處理方法都不返回值,選項c、d錯誤。選項e正確,因為如果不加super.processtextevent(te),注冊的listener將不會被喚醒。

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.

1。b、e
java的垃圾回收機制是通過一個后臺系統級線程對內存分配情況進行跟蹤實現的,對程序員來說是透明的,程序員沒有任何方式使無用內存顯示的、立即的被釋放。而且它是在程序運行期間發生的。
答案b告訴我們程序員可以使一個本地變量失去任何意義,例如給本地變量賦值為“null”;答案e告訴我們在程序運行期間不可能完全釋放內存。


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

2。d
第6行將null賦值給a以后,a以前保存的引用所指向的內存空間就失去了作用,它可能被釋放。所以對象a可能最早被垃圾回收是在第7行以前,故選擇d選項。

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.

3。b
請查閱java類庫。getid方法的返回值是“event type”。在認證考試中,總會有類似的書本以外的知識,這只能靠多實踐來增長知識了。

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.

4。a、d
控件可以同時使用多個“addxxxxlistener”方法加入多個監聽器。并且當多個監聽器加入到同一控件中時,事件可以響應多個監聽器,響應是沒有固定順序的。

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

5。d、f
本題主要考察考生對流程控制的掌握情況。這是當型循環,條件為真執行,條件為假則退出。循環體至少執行一次,故會輸出d。循環體以外的語句總會被執行,故輸出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

6。b.c
在開關語句中,標號總是不被當做語句的一部分,標號的作用就是做為條件判斷而已,一旦匹配成功,就執行其后的語句,一直遭遇break語句為止。(包括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
7。d、f
ioexception異常類是exception的子類。根據多態性的定義,ioexception對象也可以被認為是exception類型。還要注意在方法聲明中拋出異常應用關鍵字“throws”。
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

8。d
只有兩種情況:大于4時輸出“test1”,小于等于4時輸出“test3”。
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

9。a、c、d
在正常情況下,打印test1、test3、test4;在產生可捕獲異常時打印test2、test3、test4;在產生不可捕獲異常時,打印test3,然后終止程序。注意finally后面的語句總是被執行。

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

10。b
線程的執行是從方法“run( )”開始的,該方法是由系統調用的。程序員手工調用方法start(),使線程變為可運行狀態。

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{}

11。a
此題考查內部類及關鍵字“super”的用法。內部類不能與外部類同名。另外,當b繼承a時,a中的構造函數是帶參數的,b中缺省構造函數的函數體為空;而java編譯器會為空構造函數體自動添加語句“super();”調用父類構造函數,更進一步是調用父類的參數為空的構造函數。而父類中沒有參數為空的構造函數。
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

12。a
此關鍵字可以在兩個線程同時試圖訪問某一數據時避免數據毀損。
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

13。c
當一個類中未顯式定義構造函數時,缺省的構造函數是以類名為函數名,參數為空,函數體為空。雖然父類中的某一構造函數有字符串參數s,但是子類繼承父類時并不繼承構造函數,所以它只能使用缺省構造函數。故在第11行出錯。

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]

14。a、b
注意,題中問的是如何正確聲明一個一維數組,并非實例化或者初始化數組
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…}

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

16。b
靜態方法除了自己的參數外只能直接訪問靜態成員。訪問非靜態成員,必須先實例化本類的一個實例,再用實例名點取。
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

17。a、b、d
polygon的頂點信息存放在vector類型的對象內部,color定義為color,length和width定義為int。
注意,這是考試中常見的題型。
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
18。c
此題考點是高級訪問控制。請考生查閱高級訪問控制說明表格。

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

19。b
native關鍵字指明是對本地方法的調用,在java中是只能訪問但不能寫的方法,它的位置在訪問權限修飾語的后面及返回值的前面。
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?

20。final
定義常量的方法是在變量定義前加final關鍵字。
21. which is the main() method return of a application?
a. string
b. byte
c. char
d. void


21。d
main()方法沒有返回值,所以必須用void修飾。main()方法的返回值不能任意修改。
22. which is corrected argument of main() method of application?
a. string args
b. string ar[]
c. char args[][]
d. stringbuffer arg[]

22。b
main()方法的參數是字符串數組,參數名可以任意定義。
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.

23。public class employee extends person
這也是真實考試中常見的一種題型。要注意題目敘述中“is a”表示 “extends”的含義。

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(){}

24。a、b、c
考察的知識點是方法覆蓋,其中要注意的是方法覆蓋時,子類方法的訪問權限不能小于父類方法的訪問權限。另外,選項a并不是父類構造函數,它是子類中的新方法。
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)
25。a、b
考察“==”及方法“equals()”的用法。注意以下幾點區別:
1) 引用類型比較引用;基本類型比較值。
2) equals()方法只能比較引用類型,“==”可比較引用及基本類型。
3) 當用equals()方法進行比較時,對類file、string、date及封裝類(wrapper class)來說,是比較類型及內容。
4) 用“==”進行比較時,符號兩邊的數據類型必須一致(可相互轉換的基本類型除外),否則編譯出錯。

主站蜘蛛池模板: 日日摸天天摸爽爽狠狠97 | 日本50岁丰满熟妇xxxx | 狠狠躁夜夜躁青青草原 | 99久久免费看精品国产一区非洲 | 免费观看国产美女裸体视频 | 国产精品高清视亚洲精品 | 国产超碰人人做人人爽av大片 | 精品一区二区av | 免费观看欧美日韩亚洲 | 国产精品高潮呻呤 | 绯色av一区二区三区免费看 | 一女被二男吃奶a片免费观看 | 丝袜美腿亚洲一区二区 | 中文字幕11| 日本三区三区三区二区二区二区高清在线 | 另类天堂网不卡另类系列 | 国产在线播 | 一个色综合网 | 欧美一区成人 | www.三区 | 国产超碰人人模人人爽人人添 | 无码永久成人免费视频 | 延禧攻略在线看 | 国产乱人伦在线播放 | 夜色福利院在线观看免费 | 欧美一区二区在线看 | 一区二区三区 | av在线网站免费观看 | 久久精品aⅴ无码中文字字幕不卡 | 91麻豆精品国产91久久久使用方法 | 无码中文字幕AV带剧情 | 激情综合色五月丁香六月亚洲 | 久久精品国产免费看久久精品 | 欧美第一在线视频 | 琪琪五月 | 国产精品高潮呻吟久久av黑人 | 日本黄色片一级片 | 国产成人亚洲精品无码Av大片 | 50岁四川熟女露脸A片 | 精品无码人妻一区二区三区不卡 | 亚洲色无码A片一区二区情欲 |