SCJP在线测试
时间还剩:
联系我们   收藏本站   设为首页   
 
JAVA下载 JAVA文摘 J2me学习 JAVA实例              


SCJP在线测试

〖 姓名:Guest〗

第1题(id号=31):

Given the uncompleted method:
  1)
  2) { success = connect()
  3} if (success==-1) {  
  4} throw new TimedOutException();
  5} }
  6}}
  TimedOutException is not a RuntimeException. Which can complete the method of 
    declaration when added at line 1?

  A. public void method()
  B. public void method() throws Exception
  C. public void method() throws TimedOutException
  D. public void method() throw TimedOutException
  E. public throw TimedOutException void method()


请选择: A B C D E

第2题(id号=493):

Which declarations will allow a class to be started as a standalone program? 

A) public void main(String args[]) 
B) public void static main(String args[]) 
C) public static main(String[] argv) 
D) final public static void main(String [] array) 
E) public static void main(String args[]) 


请选择: A B C D E

第3题(id号=443):

What expressions are true concerning the following lines of code?
1. int[] arr = {1, 2, 3};
2. for(int i = 0 ; i < 2; i++)
3. arr[i] = 0;
Select all valid answers.
a. arr[0] == 0
b. arr[1] == 2
c. arr[1] == 0
d. arr[2] == 3


请选择: A B C D

第4题(id号=508):

Given two collection objects referenced by col1 and col2, which of 
these statements are true? 

A) The operation col1.retainAll(col2) will not modify the col1 object. 
B) The operation col1.removeAll(col2) will not modify the col2 object. 
C) The operation col1.addAll(col2) will return a new collection object, 
    containing elements from both col1 and col2. 
D) The operation col1.containsAll(Col2) will not modify the col1 object. 


请选择: A B C D

第5题(id号=388):

Consider the following code: What will be printed?
public class charTest2{
  public static void main(String[] args){
   int y = 020;
   char b = 'u0010'
   if(b==y)
     System.out.println("Char 'u0010' = 16.0");
  }
}
A. Nothing will be printed.
B. Compilation error. The char variable cannot be assigned this way.
C. Char 'u0010' = 16.0
D. Compilation error. The int variable cannot be assigned this way.
E. Compilation error. The char variable cannot be assigned this way.


请选择: A B C D E

第6题(id号=17):

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


请选择: A B C D E

第7题(id号=430):

What will appear in the standard output when you run the Tester class?
 class Tester {
   int var;
   Tester(double var) {
     this.var = (int)var;
   }

   Tester(int var) {
       this("hello");
   }

   Tester(String s) {
     this();
     System.out.println(s);
   }

   Tester() {
     System.out.println("good-bye");
   }

   public static void main(String args[]) {
      Tester t = new Tester(5);
   }

a. "hello"
b. 5
c. "hello" followed by "good-bye"
d. "good-bye" followed by "hello"


请选择: A B C D

第8题(id号=525):

Which statements concerning the switch construct are true? 

A) All switch statements must have a default label. 
B) There must be exactly one label for each code segment in a switch statement. 
C) The keyword continue can never occur within the body of a switch statement. 
D) No case label may follow a default label within a single switch statement. 
E) A character literal can be used as a value for a case label. 


请选择: A B C D E

第9题(id号=652):

Given:

class Feline {
  public static void main(String[] args) {
    Long x = 42L;
    Long y = 44L;
    System.out.print (" " + 7 + 2 + " ") ;
    System.out.print(foo () + x + 5 + " ");
    System.out.println(x + y + foo());
  }
  static String foo() { return "foo"; }
}

What is the result?

A. 9 foo47 86foo 

B. 9 foo47 4244foo 

C. 9 foo425 86foo 

D. 9 foo425 4244foo 

E. 72 foo47 86foo 

F. 72 foo47 4244foo 

G. 72 foo425 86foo 


请选择: A B C D E F G

第10题(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

第11题(id号=421):

Which one statement in true about the application below?
1. class StaticStuff {
2. static int x = 10;
3. static { x += 5; }
4. public static void main(String args[]){
5. System.out.println("x = " + x);
6. }
7. static { x /= 5; }
8. }
a. The code compiles, and execution produces the output x = 10.
b. The code compiles, and execution produces the output x = 15.
c. The code compiles, and execution produces the output x = 3.
d. Line 7 will not compile, because you can have only one static initializer.


请选择: A B C D

第12题(id号=329):

Where in a constructor, can you place a call to a constructor defined in the super class?
A. Anywhere
B. The first statement in the constructor
C. The last statement in the constructor
D. You can't call super in a constructor
Select the most appropriate answer.


请选择: A B C D

第13题(id号=504):

It is desirable that a certain method within a certain class can only
 be accessed by classes that are defined within the same package as 
the class of the method. How can such restrictions be enforced? 

A) Mark the method with the keyword public. 
B) Mark the method with the keyword protected. 
C) Mark the method with the keyword private. 
D) Mark the method with the keyword package. 
E) Do not mark the method with any accessibility modifiers. 


请选择: A B C D E

第14题(id号=183):

 int i=1,j=10; 
    do{ 
      if(i>j)continue; 
      j--; 
      }while(++i<6); 
   what are the vale of i and j? 
   A.i=6,j=5 
   B.i=5,j=5 
   C.i=6,j=4 
   D.i=5,j=6 
   E.i=6,j=6 


请选择: A B C D E

第15题(id号=675):

Given:

import java.io.*;

class Keyboard { }
public class Computer implements Serializable {
  private Keyboard k = new Keyboard();
  public static void main(String[] args)
    Computer c = new Computer();
    c.storeIt(c) ;
  }
  void storeIt(Computer c) {
    try {
      ObjectOutputStream os = new ObjectOutputStream(
         new FileOutputStream("myFile"));
      os.writeObject(c);
      os.close() ;
      System.out.println("done");
    } catch (Exception x) {System.out.println("exc"); } }
  }
}

What is the result? (Choose all that apply.)

A. exc 

B. done 

C. Compilation fails.

D. Exactly one object is serialized.

E. Exactly two objects are serialized.


请选择: A B C D E

第16题(id号=99):

 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. 


请选择: A B C D

第17题(id号=634):

Given:

1. class Plant {
2.  String getName() { return "plant"; }
3.  Plant getType() { return this; }
4. }

5. class Flower extends Plant {
6.  // insert code here
7. }
8. class Tulip extends Flower {}

Which statement(s), inserted at line 6, will compile? (Choose all that apply.)

A. Flower getType() { return this; } 

B. String getType() { return "this"; } 

C. Plant getType() { return this; } 

D. Tulip getType() { return new Tulip() ;} 


请选择: A B C D

第18题(id号=647):

Given:

1. class Example {
2.   public static void main(String[] args) {
3.     Short s = 15;
4.     Boolean b;
5.     // insert code here
6.   }
7. }

Which, inserted independently at line 5, will compile? (Choose all that apply.)

A. b = (Number instanceof s); 

B. b = (s instanceof Short); 

C. b = s.instanceof(Short); 

D. b = (s instanceof Number); 

E. b = s.instanceof(Object); 

F. b = (s instanceof String); 


请选择: A B C D E F

第19题(id号=620):

Given:

class Scoop {
  static int thrower() throws Exception { return 42; }
  public static void main(String [] args) {
    try {
      int x = thrower();
    } catch (Exception e) {
      x++;
    } finally {
      System.out.printIn("x = " + ++x);
} } }

What is the result?

A. x = 42 

B. x = 43 

C. x = 44 

D. Compilation fails.

E. The code runs with no output.


请选择: A B C D E

第20题(id号=306):

Which of the following methods from the java.awt.Graphics class could be used to 
draw the outline of a rectangle with a single method call? Select all.
A. fillRect()
B. drawRect()
C. fillPolygon()
D. drawPolygon()
E. drawLine()


请选择: A B C D E

第21题(id号=68):

What is displayed when the following code is compiled and executed?

String s1 = new String("Test");
String s2 = new String("Test");
if (s1==s2)
    System.out.println("Same");
if (s1.equals(s2))
    System.out.println("Equals");

A. Same
   Equals
B. Equals
C. Same
D. The code compiles, but nothing is displayed upon execution.
E. The code fails to compile.


请选择: A B C D E

第22题(id号=380):

Consider the following code: What will be printed?
public class booleanFlag{
  public static void main(String[] args){
    test();
    test2();
   }

  public static void test(){
    //boolean flag = false;
    if(flag=true){
      System.out.println("true");
    }else {
      System.out.println("false");
    }
  }

  public static void test2(){
    boolean flag = false;
    if(flag==true){
      System.out.println("true");
    }else {
      System.out.println("false");
    }
  }
}
A. true true
B. true false
C. false true
D. false false
E. Compilation error. Cannot resolve symbol: variable flag.


请选择: A B C D E

第23题(id号=142):

  1)public class Test{ 
   2)public static void main(String[] args){ 
   3) class Foo{ 
   4) public int i=3; 
   5) } 
   6) Object o=(Object)new Foo(); 
   7) Foo foo=(Foo)o; 
      System.out.println(foo.i); 
   9) } 
   10) } 
  what is result? 
  A.compile error at line 6 
  B.compile error at line 7 
  C.print out 3 


请选择: A B C

第24题(id号=38):

Which of the following statements about variables and their scopes are true?
  A. Instance variables are member variables of a class.
  B. Instance variables are declared with the static keyword.
  C. Local variables defined inside a method are created when the method is executed.
  D. Local variables must be initialized before they are used.
  


请选择: A B C D

第25题(id号=672):

Given that bw is a reference to a valid BufferedWriter 

And the snippet:

15.  BufferedWriter b1 = new BufferedWriter(new File("f"));
16.  BufferedWriter b2 = new BufferedWriter(new FileWriter("f1"));
17.  BufferedWriter b3 = new BufferedWriter(new PrintWriter("f2"));
18.  BufferedWriter b4 = new BufferedWriter(new BufferedWriter(bw));

What is the result?

A. Compilation succeeds.

B. Compilation fails due only to an error on line 15.

C. Compilation fails due only to an error on line 16.

D. Compilation fails due only to an error on line 17.

E. Compilation fails due only to an error on line 18.

F. Compilation fails due to errors on multiple lines.


请选择: A B C D E F

第26题(id号=470):

What is the result of attempting to compile and run the following program?
 public class AStringQuestion {
  static String s1;
  static String s2;
  public static void main(String args[]){
    s2 = s1+s2;
    System.out.println(s2);
 }
}
Select one correct answer
a. Will cause a compilation error.
b. Runtime Execption -NullPointerException in the 2nd line of the main method.
c. Will compile successfully and print "nullnull" on the screen.
d. Will compile successfully and print an empty line on the screen.


请选择: A B C D

第27题(id号=129):

float f=4.2F;
Float g=new Float(4.2F);
Double d=new Double(4.2);
Which are true?
A. f==g   B. g==g   C. d==f   D. d.equals(f)  E d.equals(g)  F. g.equals(4.2);


请选择: A B C D E F

第28题(id号=556):


  Which are syntactically valid statement at// point x? 
  class Person {
    private int a;
    public int change(int m){ return m; }
  }
  public class Teacher extends Person {
    public int b;
    public static void main(String arg[]){
     Person p = new Person();
     Teacher t = new Teacher();
     int i;
     // point x
   }
  }
  A. i = m;
  B. i = b;
  C. i = p.a; 
  D. i = p.change(30);
  E. i = t.b. 


请选择: A B C D E

第29题(id号=524):

Which operators will always evaluate all the operands? 

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


请选择: A B C D E

第30题(id号=713):

Which are methods of the Object class? (Choose all that apply.)

A. notify(); 

B. notifyAll(); 

C. isInterrupted(); 

D. synchronized(); 

E. interrupt(); 

F. wait(long msecs); 

G. sleep(long msecs); 


请选择: A B C D E F G

第31题(id号=340):

Using a FlowLayout manager, which is the correct way to add elements to a container:
A. add(component);
B. add("Center", component);
C. add(x, y, component);
D. set(component);
Select the most appropriate answer.


请选择: A B C D

第32题(id号=170):

 1)public class Foo implements Runnable{ 
  2)  public void run(Thread t){ 
     System.out.println("Running"); 
      } 
    public static void main(String[] args){ 
     new Thread(new Foo()).start(); 
     } 
     } 
   what is the result? 
   A.An Exception is thrown 
   B.The program exits without printing anything 
   C.An error at line 1 causes complication to fail 
   D.An error at line 2 causes complication to fail 
   E."Running" is pinted and the program exits 


请选择: A B C D E

第33题(id号=87):

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


请选择: A B C D

第34题(id号=321):

Under what situations do you obtain a default constructor?
A. When you define any class
B. When the class has no other constructors
C. When you define at least one constructor
Select the most appropriate answer.


请选择: A B C

第35题(id号=120):

 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. 


请选择: A B C D

第36题(id号=563):

Given:
1. public class NewGarb {
2. public static Object getIt() {
3. Object rg = new Integer(3);
4. Object dg[][] = new Object[1][2];
5. dg[0][1] = rg;
6. dg[0][0] = rg;
7. rg = null;
8. return rg;
9. }
10. }Which statement is true?
A The NewGarb class will not compile.
B The getIt() method must not be declared as static.
C The NewGarb class compiles, but receives an exception because 
  dg is not set to null.
D The rg object is eligible for garbage collection after a call 
  to the getIt() method has returned.


请选择: A B C D

第37题(id号=679):

2.  
 Given:

public static void main(String[] args) {

  // INSERT DECLARATION HERE
  for (int i = 0; i <= 10; i++) {
    List<Integer> row = new ArrayList<Integer>();
    for (int j = 0; j <= 10; j++)
      row.add(i * j);
    table.add(row);
  }
  for (List<Integer> row : table)
    System.out.println(row);
  }


Which statements could be inserted at // INSERT DECLARATION HERE to allow 
this code to compile and run? (Choose all that apply.)

A. List<List<Integer>> table = new List<List<Integer>>(); 

B. List<List<Integer>> table = new ArrayList<List<Integer>>(); 

C. List<List<Integer>> table = new ArrayList<ArrayList<Integer>>(); 

D. List<List, Integer> table = new List<List, Integer>(); 

E. List<List, Integer> table = new ArrayList<List, Integer>(); 

F. List<List, Integer> table = new ArrayList<ArrayList, Integer>(); 

G. None of the 


请选择: A B C D E F G

第38题(id号=45):

Which statements about Java code security are true?
  A. The bytecode verifier loads all classes needed for the execution of a program.
  B. Executing code is performed by the runtime interpreter.
  C. At runtime the bytecodes are loaded, checked and run in an interpreter.
  D. The class loader adds security by separating the namespaces for the classes of 
       the local file system from those imported from network sources.
  


请选择: A B C D

第39题(id号=208):

Given the following declaration
  String s = "Example";
  Which are legal code?
A. s >>> = 3;
B. s[3] = "x";
C. int i = s.length();
D. String t = "For " + s;
E. s = s + 10;


请选择: A B C D E

第40题(id号=387):

Consider the following code: What will happen when you try to compile it?
public class InnerClass{
 public static void main(String[]args)
  {}
 public class MyInner{
 }}
A. It will compile fine.
B. It will not compile, because you cannot have a public inner class.
C. It will compile fine, but you cannot add any methods, because then 
   it will fail to compile.


请选择: A B C

第41题(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

第42题(id号=212):

Which modifier should be applied to a method for the lock of the
  object this to be obtained prior to executing any of the method body?
A. final
B. static
C. abstract
D. protected
E. synchronized


请选择: A B C D E

第43题(id号=418):

You are creating a ToolBase class which will be extended by other programmers.
The ToolBase class contains a single abstract method, createTool.
Which of the following statements are true?
a. The ToolBase class must be declared abstract.
b. Classes extending ToolBase must not be declared abstract.
c. The ToolBase class must not be declared final.
d. The following variable declaration is illegal in any context "ToolBase myTB;"


请选择: A B C D

第44题(id号=288):

The following code will print:

1: int i=1;
2: i<<=31;
3: i>>=31;
4: i>>=1;
5:
6: int j=1;
7: j<<=31;
8: j>>=31;
9:
10 System.out.println("i="+i);
11 System.out.println("j="+j);

Select all valid answer.
A. i=1
   j=1

B. i=-1
   j=1

C. i=1
   j=-1

D. i=-1
   j=-1


请选择: A B C D

第45题(id号=316):

Which of the following are so called "short circuit" logical operators?
A. &
B. ||
C. &&
D. |
Select all correct answers.


请选择: A B C D

第46题(id号=510):

Which statements concerning the value of a member variable are true, 
when no explicit assignments have been made? 

A) The value of an int is undetermined. 
B) The value of all numeric types is zero. 
C) The compiler may issue an error if the variable is used before it is initialized. 
D) The value of a String variable is "" (empty string). 
E) The value of all object variables is null. 


请选择: A B C D E

第47题(id号=349):

What is the result of executing the following code when the value of x is 2:
switch (x) {
 case 1:
  System.out.println(1);
 case 2:
 case 3:
  System.out.println(3);
 case 4:
  System.out.println(4);
}
A. Nothing is printed out
B. The value 3 is printed out
C. The values 3 and 4 are printed out
D. The values 1, 3 and 4 are printed out
Select the most appropriate answer.


请选择: A B C D

第48题(id号=82):

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 


请选择: A B C D

第49题(id号=721):

Given these classes in different files:

package xcom;
public class Useful {
  int increment(int x) { return ++x; }
}

import xcom.*;                               // line 1
class Needy3 {
  public static void main(String[] args) {
    xcom.Useful u = new xcom.Useful();       // line 2
    System.out.println(u.increment(5));
  }
}

Which statements are true? (Choose all that apply.)

A. The output is 0.

B. The output is 5.

C. The output is 6.

D. Compilation fails.

E. The code compiles if line 1 is removed.

F. The code compiles if line 2 is changed to read

    Useful u = new Useful( );


请选择: A B C D E F

第50题(id号=331):

What class must an inner class extend:
A. The top level class
B. The Object class
C. Any class or interface
D. It must extend an interface
Select the most appropriate answer.


请选择: A B C D

第51题(id号=503):

Which of these are keywords in Java? 

A) default 
B) NULL 
C) String 
D) throws 
E) long 


请选择: A B C D E

第52题(id号=352):

Consider the following classes:
public class Test {
 public static void test() {
  this.print();
}
 public static void print() {
  System.out.println("Test");
}
public static void main(String args []) {
 test();
} }
What is the result of compiling and running this class?
A. The string Test is printed to the standard out.
B. A runtime exception is raised stating that an object has not been created.
C. Nothing is printed to the standard output.
D. An exception is raised stating that the method test cannot be found.
E. An exception is raised stating that the variable this can only be used within an
   instance.
F. The class fails to compile stating that the variable this is undefined.
   Select all correct answers.


请选择: A B C D E F

第53题(id号=282):

Consider this class example:
class MyPoint {
  void myMethod(){
   int x, y;
   x = 5; y = 3;
   System.out.print("(" + x + ", " + y + ")");
   switchCoords(x,y);
   System.out.print("(" + x + ", " + y + ")");
  }
  void switchCoords(int x,int y){
   int temp;
   temp = x;
   x = y;
   y = temp;
   System.out.print("(" + x + ", " + y + ")");
  }
}
What is printed to standard output if myMethod() is executed?
A. (5, 3) (5, 3) (5, 3)
B. (5, 3) (3, 5) (3, 5)
C. (5, 3) (3, 5) (5, 3)


请选择: A B C

第54题(id号=169):

 which two cannot directly cause a thread to stop executing? 
  A.calling the yield method 
  B.calling the wait method on an object 
  C.calling the notify method on an object 
  D.calling the notifyAll method on an object   
  E.calling the start method on another thread object 


请选择: A B C D E

第55题(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

第56题(id号=299):

If s1 is declared as:
  String sl = "phenobarbital";
What will be the value of s2 after the following line of code:
String s2 = s1.substring( 3, 5 );
A. null
B. "eno"
C. "enoba"
D. "no"


请选择: A B C D E

第57题(id号=442):

What is written to the standard output given the following statement
1. System.out.println(4 | 7);
a. 4
b. 5
c. 6
d. 7


请选择: A B C D

第58题(id号=200):

Given: 
1. package foo; 
2.   
3. public class Outer { 
4.    public static class Inner{ 
5.    }
6. }
Which statement is true? 
A. An instance of the Inner class can be constructed with “new Outer.Inner ()” 
B. An instance of the inner class cannot be constructed outside of package foo 
C. An instance of the inner class can only be constructed from within the outer class 
D. From within the package foo, an instance of the inner class can be constructed with 
   “new inner()” 



请选择: A B C D

第59题(id号=542):

Given the following code:
1) public void modify() {
2) int i, j, k;
3) i = 100;
4) while ( i > 0 ) {
5) j = i * 2;
6) System.out.println (" The value of j is " + j );
7) k = k + 1;
8) i--;
9) }
10) }
Which line might cause an error during compilation?
A. line 4
B. line 6
C. line 7
D. line 8


请选择: A B C D

第60题(id号=447):

Consider the following
1. class A extends Integer {
2. int x = 0;
3. }
a. The code will compile correctly.
b. The code will not compile because Integer class is final.
c. The code will not compile because A class doesn't have a constructor.
d. The code will compile but an ArithmeticException at runtime.


请选择: A B C D


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