SCJP在线测试

SCJP在线测试

〖 姓名:weiking〗

第1题(id号=361):

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. Prints out "Sample"
B. Program produces no output but terminates correctly.
C. Program does not terminate.
D. The program will not compile
Select the most appropriate answer.


请选择: A B C D

第2题(id号=239):

Which are keywords in Java?
A. NULL
B. sizeof
C. friend
D. extends
E. synchronized


请选择: A B C D E

第3题(id号=410):

In the following applet, how many buttons will be displayed?
 import java.applet.*;
 import java.awt.*;
 public class Q16 extends Applet {
    Button okButton = new Button("Ok");
    public void init() {
      add(okButton);
      add(okButton);
      add(okButton);
      add(okButton);
      add(new Button("Cancel"));
      add(new Button("Cancel"));
      add(new Button("Cancel"));
      add(new Button("Cancel"));
      setSize(300,300);
   }
 }
a. 1 Button with label "Ok" and 1 Button with label "Cancel".
b. 1 Button with label "Ok" and 4 Buttons with label "Cancel".
c. 4 Buttons with label "Ok" and 1 Button with label "Cancel".
d. 4 Buttons with label "Ok" and 4 Buttons with label "Cancel".


请选择: A B C D

第4题(id号=455):

What is displayed when the following piece of code is executed.
 class Test extends Thread {
   public void run() {
     System.out.print("1 ");
     yield();
     System.out.print("2 ");
     suspend();
     System.out.print("3 ");
     resume();
     System.out.print("4 ");
 }
 public static void main(String []args){
   Test t = new Test();
   t.start();
 }
}
a. Nothing, this is not a valid way to create and start a thread.
b. 1 2
c. 1 2 3
d. 1


请选择: A B C D

第5题(id号=405):

You are working on an aquarium simulation class named Aquarius. You already 
have a method which adds a Fish object to the aquarium and returns the 
remaining fish capacity. This method has the following declaration.
public int addFish( Fish f )
Now you want to provide for adding a whole shoal of fish at once. The proposed 
method declaration is
protected boolean addFish( Fish[] f )
The idea being that it will return true if there is more room in the tank or 
false if the tank now too full. Which of the following statements about this 
proposal are true?
a. This technique is called overloading.
b. This technique is called overriding.
c. The compiler will reject the new method because the return type is 
   different.
d. The compiler will reject the new method because the access modifier is 
   different.


请选择: A B C D

第6题(id号=168):

 You need to store elements in a collection that guarantees that no duplicates 
   are stored and all elements can be access in nature order, which interace 
   provides that capability? 
   A. java.uil.Map 
   B.java.util.Set 
   C.java.util.List 
   D.java.util.SortedSet 
   E.java.util.SortedMap 
   F.java.util.Collection 


请选择: A B C D E F

第7题(id号=55):

Given the following code:
  1) class Parent {
  2} private String name;
  3} public Parent(){}
  4} }
  5) public class Child extends Parent {
  6} private String department;
  7} public Child() {}
  8} public String getValue(){ return name; }
  9) public static void main(String arg[]) {
  10} Parent p = new Parent();
  11} }
  12) }
  Which line will cause error?
  A. line 3
  B. line 6
  C. line 7
  D. line 8
  E. line 10


请选择: A B C D E

第8题(id号=576):

Given the following code:
class Tester {
 public static void main(String[] args){
  CellPhone cell = new CellPhone();
  cell.emergency();
 }
}

class Phone {
 final void dial911() {
 // code to dial 911 here . . .
} }

class CellPhone extends Phone {
 void emergency() {
  dial911();
 }
}

What will happen when you try to compile and run the Tester class?
a) The code will not compile because Phone is not also declared as final.
b) The code will not compile because you cannot invoke a final method 
   from a subclass.
c) The code will compile and run fine.
d) The code will compile but will throw a NoSuchMethodException when 
   Tester is run.
e) Phone and CellPhone are fine, but Tester will not compile because it cannot create 
   an instance of a class that derives from a class defining a final method.


请选择: A B C D E

第9题(id号=322):

Given the following code:
public class Test {
   … }
Which of the following can be used to define a constructor for this class:
A. public void Test() {… }
B. public Test() {… }
C. public static Test() {… }
D. public static void Test() {… }
Select the most appropriate answer.


请选择: A B C D

第10题(id号=97):

  Which are Java keyword? 
   A. goto 
   B. null 
   C. FALSE 
   D. native 
   E. const 


请选择: A B C D E

第11题(id号=334):

What is the name of the method used to schedule a thread for execution?
A. init();
B. start();
C. run();
D. resume();
E. sleep();
Select the most appropriate answer.


请选择: A B C D E

第12题(id号=150):

public class X{ 
    private static int a; 
    public static void main(String[] args){ 
     modify(a); 
     System.out.println(a); 
     } 
    public static void modify(int a){ 
      a++; 
     } 
     } 
   what is the result? 
A. 0
B. 1


请选择: A B

第13题(id号=229):

What is the target in an Event?
A. The Object() where the event came from.
B. The Object() where the event is destined for.
C. What the Object() that generated the event was doing.


请选择: A B C

第14题(id号=406):

You have created a TimeOut class as an extension of Thread, the purpose being to print 
a "Time's Up" message if the Thread is not interrupted within 10 seconds of being 
started. Here is the run method which you have coded.
1. public void run(){
2. System.out.println("Start!");
3. try {
4. Thread.sleep(10000 );
5. System.out.println("Time's Up!");
6. } catch(InterruptedException e) {
7. System.out.println("Interrupted!");
8. }
9. }
Given that a program creates and starts a TimeOut object, which of the following 
statements is true?
a. Exactly 10 seconds after the start method is called, "Time's Up!" will be printed.
b. Exactly 10 seconds after "Start!" is printed, "Time's Up!" will be printed.
c. The delay between "Start!" being printed and "Time's Up!" will be 10 seconds plus or 
   minus one tick of the system clock.
d. If "Time's Up!" is printed you can be sure at least 10 seconds have elapsed 
   since "Start!" was printed.


请选择: A B C D

第15题(id号=108):

 public class Foo{ 
  public static void main(String args[]){ 
  try{return;} 
   finally{ System.out.println("Finally");} 
   } 
    } 
 what is the result? 
 A. print out nothing 
 B. print out "Finally" 
 C. compile error 


请选择: A B C

第16题(id号=149):

 public class Test{ 
   static void leftshift(int i, int j){ 
      i<<=j; 
     } 
   public static void main(String args[]){ 
      int i=4, j=2; 
      leftshift(i,j); 
      System.out.println(i); 
     } 
     } 
   what is the result? 
A. 16
B. 4


请选择: A B

第17题(id号=412):

What will happen if you compile/run the following code?
 public class Q21 {
  int maxElements;
  void Q21() {
   maxElements = 100;
   System.out.println(maxElements);
 }
  Q21(int i) {
   maxElements = i;
   System.out.println(maxElements);
 }
 public static void main(String[] args) {
   Q21 a = new Q21();
   Q21 b = new Q21(999);
 }
}
a. Prints 100 and 999.
b. Prints 999 and 100.
c. Compilation error


请选择: A B C

第18题(id号=568):

1. import java.awt.*;
2.
3. public class Birthdays extends Frame {
4. Birthdays() {
5. super("Birthday Reminder");
6. String lblsP1[] = {"Name:", "Birthday:", "Address:"};
7. String butnsP2[] = {"Add", "Save", "Exit"};
8. Panel panelTop = new Panel();
9. Panel panelBot = new Panel();
10. panelTop.setLayout(new GridLayout(3,2,3,3));
11. for(int x = 0; x < lblsP1.length; x++) {
12. panelTop.add(new Label(lblsP1[x]));
13. panelTop.add(new TextField());
14. }
15. for(int y = 0; y < butnsP2.length; y++) {
16. panelBot.add(new Button(butnsP2[y]));
17. }
18. add(panelTop, BorderLayout.NORTH);
19. add(panelBot, BorderLayout.SOUTH);
20. }
21. }
Which main method should you add to the Birthdays class to allow the program to
compile and run with all defined fields properly displayed?
A public static void main(String args[]) {
    Frame.visible = true;
  }
B public static void main(String args[]) {
    Frame f = new Frame();
    f.setVisible(true);
  }
C public static void main(String args[]) {
    Birthdays b = new Birthdays();
    b.pack();
    b.setVisible(true);
  }
D public static void main(String args[]) {
    Frame f = Birthdays.new Frame();
    f.pack();
    f.visible = true;
  }


请选择: A B C D

第19题(id号=56):

The variable "result" is boolean. Which expressions are legal?
A. result = true;
B. if ( result ) { // do something... }
C. if ( result!= 0 ) { // so something... }
D. result = 1


请选择: A B C D

第20题(id号=134):

 What is "is a" relation? 
  A.public interface Color{} 
    public class Shape{private Color color;} 
  B.interface Component{} 
    class Container implements Component{ 
     private Component[] children; 
      } 
  C.public class Species{} 
     public class Animal{private Species species;}   
  D.interface A{} 
    interface B{} 
    interface C implements A,B{}   //syntex error 


请选择: A B C D

第21题(id号=524):

Which operators will always evaluate all the operands? 

1) || 
2) + 
3) && 
4) ? : 
5) % 


请选择: A B C D E

第22题(id号=291):

Which of the following are methods of the Collection interface?
A.iterator
B.isEmpty
C.toArray
D.setText


请选择: A B C D

第23题(id号=500):

Which statements can be inserted at the indicated position in the following 
code to make the program write 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(); 
  } 


A) a = b; 
B) c = this.a; 
C) c = this.b; 
D) c = Q4a39.this.a; 
E) c = c; 


请选择: A B C D E

第24题(id号=606):

What access control keyword should you use to allow other classes to
access a method freely within its package, but to restrict classes outside
of the package from accessing that method?
Select all valid answers.
a) public
b) protected
c) private
d) do not supply an access control keyword


请选择: A B C D

第25题(id号=202):

 Which three are valid declarations of a float? (Choose  Three) 
A. float foo = -1; 
B. float foo = 1.0; 
C. float foo = 42e1; 
D. float foo = 2.02f; 
E. float foo = 3.03d; 
F. float foo = 0x0123; 


请选择: A B C D E F

第26题(id号=248):

Given the following code, what is the output when a exception other
than a NullPointerException is thrown?
try{
  //some code
}catch(NullPointerException e) {
  System.out.println("thrown 1");
}finally {
  System.out.println("thrown 2");
}
System.out.println("thrown 3");
A thrown 1
B thrown 2
C thrown 3
D none


请选择: A B C D

第27题(id号=379):

Consider the following code: What will be printed?
public class ArrayTest3{
  public static void main(String[]args){
    int [][] a = new int[5][5];
    System.out.println(a[4][4]);
  }
}
A. 0 0 0 0
B. 0 0
C. 0
D. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0


请选择: A B C D

第28题(id号=345):

Which of the following illustrates the correct way to pass a parameter into an applet:
A. <applet code=Test.class age=33 width=100 height=100>
B. <param name=age value=33>
C. <applet code=Test.class name=age value=33 width=100 height=100>
D. <applet Test 33>
Select the most appropriate answer.


请选择: A B C D

第29题(id号=145):

1)public class Test{ 
  2) public static void main(String[] args){ 
  3) unsigned byte b=0; 
  4) b--; 
  5) 
  6) } 
  7) } 
  what is the value of b at line 5? 
  A.-1   B.255  C.127  D.compile fail  E.compile succeeded but run error 


请选择: A B C D E

第30题(id号=269):

You are going to read some rows one by one from a file that is
stored locally on your hard drive. How do you do it?
A. BufferedReader
B. InputStreamReader
C. One reader with "8859-1" as an argument
D. Don't remember
E. FileReader


请选择: A B C D E

第31题(id号=337):

Given the following code what is the effect of a being 5:
public class Test {
 public void add(int a) {
   loop: for (int i = 1; i < 3; i++){
   for (int j = 1; j < 3; j++) {
    if (a == 5) {
        break loop;
    }
    System.out.println(i * j);
} } } }
A. Generate a runtime error
B. Throw an ArrayIndexOutOfBoundsException
C. Print the values: 1, 2, 2, 4
D. Produces no output
Select the most appropriate answer.


请选择: A B C D

第32题(id号=244):

Which statements on the<<< call>>> line are valid expressions?
public class SuperClass {
  public int x;
  int y;
  public void m1 (int a) {
  }
  Superclass(){
  }
}

class SubClass extends SuperClass{
 private float f;
 void m2() {
  return;
 }
 SubClass() {
 }
}

class T {
  public static void main (String [] args) {
   int i;
   float g;
   SubClass b = SubClass();
   <<< calls >>>
  }
}
A. b.m2();
B. g=b.f;
C. i=b.x;
D. i=b.y;
E. b.m1(6);


请选择: A B C D E

第33题(id号=541):

In the Java API documentation which sections are included in a class document?
A. The description of the class and its purpose
B. A list of methods in its super class
C. A list of member variable
D. The class hierarchy


请选择: A B C D

第34题(id号=318):

What is the result of compiling and running the following code:
public class Test {
  static int total = 10;
  public static void main (String args []) {
    new Test();
  }
  public Test () {
   System.out.println("In test");
   System.out.println(this);
   int temp = this.total;
   if (temp > 5) {
     System.out.println(temp);
   } } }
A. The class will not compile
B. The compiler reports and error at line 2
C. The compiler reports an error at line 9
D. The value 10 is one of the elements printed to the standard output
E. The class compiles but generates a runtime error
Select all correct answers.


请选择: A B C D E

第35题(id号=535):

The 8859-1 character code for the uppercase letter A is 65. Which of 
these code fragments declare and initialize a variable of type char with this value? 

A) char ch = 65; 
B) char ch = '\65' 
C) char ch = '\0041' 
D) char ch = 'A' 
E)char ch = "A"; 


请选择: A B C D E

第36题(id号=413):

Given the following class definition,which of the following methods could be legally 
placed after the comment //Here
1. public class Rid {
2. public void amethod(int i, String s){}
3. //Here
4. }
a. public void amethod(String s, int i){}
b. public int amethod(int i, String s){}
c. public void amethod(int i, String mystring) {}
d. public void Amethod(int i, String s){}



请选择: A B C D

第37题(id号=323):

Which of the following are acceptable to the Java compiler:
A. if (2 == 3) System.out.println("Hi");
B. if (2 = 3) System.out.println("Hi");
C. if (true) System.out.println("Hi");
D. if (2 != 3) System.out.println("Hi");
E. if (aString.equals("hello")) System.out.println("Hi");
Select all correct answers.


请选择: A B C D E

第38题(id号=383):

Consider the following code: What will be printed?
public class Equal{
  public static void main(String kyckling[]){
   int Output = 10;
   boolean b1 = false;
   if((b1==true) && ((Output+=10)==20)){
      System.out.println("We are equal " + Output);
   }else{
      System.out.println("Not equal! " + Output);
   }
}}
A. Nothing will be printed. You must use the word args instead of kyckling in 
   the main method.
B. We are equal 10
C. Not equal 10
D. We are equal 20
E. Not equal 20


请选择: A B C D E

第39题(id号=8):

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 B C D E

第40题(id号=17):

Which are not Java keywords? 
A. TRUE
B. sizeof
C. const
D. super
E. void 


请选择: A B C D E

第41题(id号=497):

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


a) 9 
b) 18 
c) 20 
d) 21 
e) 22 


请选择: A B C D E

第42题(id号=558):

Given the following code fragment:
  1) public void create() {
  2) Vector myVect;
  3) myVect = new Vector(); 
  4) }
  Which of the following statements are true? 
  A. The declaration on line 2 does not allocate memory space for the
        variable myVect.
  B. The declaration on line 2 allocates memory space for a reference 
        to a Vector object.
  C. The statement on line 2 creates an object of class Vector.
  D. The statement on line 3 creates an object of class Vector.
  E. The statement on line 3 allocates memory space for an object of class Vector


请选择: A B C D E

第43题(id号=262):

Which interface should you use if you want no duplicates, no order
and no particular retrieval system?
A. Map
B. Set
C. List
D. Collection
E. Enumeration


请选择: A B C D E

第44题(id号=354):

What is the result of compiling and executing the following Java class:
public class ThreadTest extends Thread {
 public void run() {
  System.out.println("In run");
  suspend();
  resume();
  System.out.println("Leaving run");
}
public static void main(String args []) {
  (new ThreadTest()).start();
} }
A. Compilation will fail in the method main.
B. Compilation will fail in the method run.
C. A warning will be generated for method run.
D. The string "In run" will be printed to standard out.
E. Both strings will be printed to standard out.
F. Nothing will happen.
Select the most appropriate answer.


请选择: A B C D E F

第45题(id号=402):

Select all of the following methods that are instance methods of the Thread class, 
excluding any methods deprecated in Java1.2.
a. start()
b. stop()
c. run()
d. suspend()
e. sleep( long msec )
f. toString()


请选择: A B C D E F

第46题(id号=540):

Given the following code:
 public class Test {
  void printValue(int m){
   do {
        System.out.println("The value is"+m);
  }while( --m > 10 )
 }
 public static void main(String arg[]) {
  int i=10;
  Test t= new Test();
  t.printValue(i);
 }
}
Which will be output?
A. The value is 8
B. The value is 9
C. The value is 10
D. The value is 11


请选择: A B C D

第47题(id号=278):

Which of the following describe the sequence of method calls that
result in a component being redrawn?
A. invoke paint() directly
B. invoke update which calls paint()
C. invoke repaint() which invokes update(), which in turn invokes paint()
D. invoke repaint() which invokes paint() directly


请选择: A B C D

第48题(id号=14):

Which layout manager is used when the frame is resized the buttons's position in the 
 Frame might be changed? 

A. BorderLayout
B. FlowLayout
C. CardLayout
D. GridLayout


请选择: A B C D

第49题(id号=241):

What can contain objects that have a unique key field of String
type, if it is required to retrieve the objects using that key field as an index?
A. Map
B. Set
C. List
D. Collection
E. Enumeration


请选择: A B C D E

第50题(id号=547):

Given the following code:
public class Person{
 static int arr[] = new int[10];
 public static void main(String a[]) {
 System.out.println(arr[1];)
}
}
Which statement is correct?
A. When compilation some error will occur.
B. It is correct when compilation but will cause error when running.
C. The output is zero.
D. The output is null.


请选择: A B C D

第51题(id号=126):

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 


请选择: A B C D E

第52题(id号=377):

Consider the following code: What will be printed?
public class Arraytest{
  public static void main(String kyckling[]){
    Arraytest a = new Arraytest();
    int i[] = new int[5];
    System.out.println(i[4]);
    a.amethod();
    Object o[] = new Object[5];
    System.out.println(o[2]);
  }

 void amethod(){
   int K[] = new int[4];
   System.out.println(K[3]);
 }
}
A. null null null
B. null 0 0
C. 0 0 null
D. 0 null 0


请选择: A B C D

第53题(id号=434):

What access control keyword should you use to enable other classes to access a
method freely within its package, but to restrict classes outside of the package
from accessing that method? Select all valid answers.
a. private
b. public
c. protected
d. Do not supply an access control keyword (friendly).


请选择: A B C D

第54题(id号=7):

 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. 


请选择: A B

第55题(id号=137):

1)public class X implements Runnable{ 
  2)private int x; 
  3)private int y; 
  4)public static void main(String[] args){ 
  5)   X that =new X(); 
  6) (new Thread(that)).start(); 
  7) (new Thread(that)).start(); 
   } 
  9) public synchronized void run(){ 
  10)  for(;;){ 
  11)      x++; 
  12)      Y++; 
  13) System.out.println("x="+x+",y="+y); 
  14)    } 
  15)   } 
  16)  }   
    what is the result? 
  A.compile error at line 6 
  B.the program prints pairs of values for x and y that are 
    always the same on the same time 


请选择: A B

第56题(id号=5):

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 B C D E

第57题(id号=439):

Which keyword, when used in front of a method, must also appear in front of the class.
a. synchronized
b. abstract
c. public
d. private


请选择: A B C D

第58题(id号=33):

Which classes can be used as the argument of the constructor of the class 
FileInputStream?
  A. InputStream
  B. File
  C. FileOutputStream
  D. String


请选择: A B C D

第59题(id号=75):

 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 


请选择: A B C D

第60题(id号=207):

 Which declaration prevents creating a subclass of an outer class? 
A. static class FooBar{} 
B. private class FooBar{} 
C. abstract public class FooBar{} 
D. final public class FooBar{} 
E. final abstract class FooBar{} 



请选择: A B C D E


如果你想交卷,请点击提交按钮:


http://www.java3z.com/cwbwebhome/dir1/javaSCJP/examination1.jsp
weiking   2006-04-20 21:26:04 评论:1   阅读:695   引用:0
@2006-12-06 12:54:01  游客
////////////////////////

发表评论>>

署名发表(评论可管理,不必输入下面的姓名)

姓名:

主题:

内容: 最少15个,最长1000个字符

验证码: (如不清楚,请刷新)

用,就用的漂亮点。文章嘛,借花献佛喽。