站内搜索
SCJP程序员认证考试 问题列表
问题 单选题1. public class GoTest {  2. public static void main(String[] args) {  3. Sente a = new Sente(); a.go();  4. Goban b = new Goban(); b.go();  5. Stone c = new Stone(); c.go();  6. }  7. } 8.  9. class Sente implements Go {  10. public void go() { System.out.println(”go in Sente.”); }  11. }  12.  13. class Goban extends Sente {  14. public void go() { System.out.println(”go in Goban”); }  15. }  16.  17. class Stone extends Goban implements Go { }  18.  19. interface Go { public void go(); }  What is the result?()A  go in Goban  go in Sente go in SenteB  go in Sente  go in Sente go in GobanC  go in Sente  go in Goban go in GobanD  go in Goban go in Goban go in SenteE  Compilation fails because of an error in line 17.

问题 单选题public class ExceptionTest {   class TestException extends Exception {}   public void runTest () throws TestException {}   public void test () /* Point X*/ {   runTest ();   }   }   At point X on line 4, which code can be added to make the code compile?()A  Throws Exception.B  Catch (Exception e).C  Throws RuntimeException.D  Catch (TestException e).E  No code is necessary.

问题 单选题Given that the current directory is empty, and that the user has read and write privileges to the current directory, and the following: Which statement is true?()A Compilation fails.B Nothing is added to the file system.C Only a new file is created on the file system.D Only a new directory is created on the file system.E Both a new file and a new directory are created on the file system.

问题 单选题class MyThread extends Thread {  public void run() { System.out.println(“AAA”); }  public void run(Runnable r) { System.out.println(“BBB”); }  public static void main(String[] args) {  new Thread(new MyThread()).start();  }  }   What is the result?()A  AAAB  BBBC  Compilation fails.D  The code runs with no output.

问题 填空题Write a line of code that declares a variable named layout of type LayoutManager and initializes it with a new object, which when used with a container can lay out components in a rectangular grid of equal-sized rectangles, 3 components wide and 2 components high.()

问题 多选题Which four are true?()AHas-a relationships should never be encapsulated.BHas-a relationships should be implemented using inheritance.CHas-a relationships can be implemented using instance variables.DIs-a relationships can be implemented using the extends keyword.EIs-a relationships can be implemented using the implements keyword.FAn array or a collection can be used to implement a one-to-many has-a relationship.GThe relationship between Movie and Actress is an example of an is-a relationship.

问题 单选题An instance member()A is also called a static memberB is always a variableC is never a methodD belongs to a single instance, not to the class as a wholeE always represents an operation

问题 单选题interface Data { public void load(); }  abstract class Info { public abstract void load(); }  Which class correctly uses the Data interface and Info class?()A  public class Employee extends Info implements Data { public void load() { /*do something*/ } }B  public class Employee implements Info extends Data { public void load() { /*do something*/ } }C  public class Employee extends Info implements Data { public void load() { /*do something */ } public void Info.load() { /*do something*/ } }D  public class Employee implements Info extends Data { public void Data.load() { /*dsomething */ } public void load() { /*do something */ } }E  public class Employee implements Info extends Data { public void load() { /*do something */ } public void Info.load(){ /*do something*/ } }F  public class Employee extends Info implements Data{ public void Data.load() { /*do something*/ } public void Info.load() { /*do something*/ } }

问题 多选题public class test {  public static void main(String [] a) {  assert a.length == 1;  }  }  Which two will produce an AssertionError?()Ajava testBjava -ea testCjava test file1Djava -ea test file1Ejava -ea test file1 file2Fjava -ea:test test file1

问题 单选题What happens when thread X executes a wait() method on object A, without owning object A’s lock?()A  Compilation fails.B  An exception is thrown.C  The wait() method has no effect.D  Thread X receives the lock immediately.E  Object A moves the thread to the wait pool.

问题 单选题What is the numerical range of a char?()A  0 . . . 32767B  0 . . . 65535C  –256 . . . 255D  –32768 . . . 32767E  Range is platform dependent.

问题 多选题1. class BaseClass {  2. private float x = 1.of;  3. protected float getVar() { return x; }  4. }  5. class SubClass extends BaseClass {  6. private float x = 2.Of;  7. // insert code here 8. }   Which two are valid examples of method overriding when inserted at line 7?()Afloat getVar() { return x; }Bpublic float getVar() { return x; }Cpublic double getVar() { return x; }Dprotected float getVar() { return x; }Epublic float getVar(float f) { return f; }

问题 多选题Given the following code, which code fragments, when inserted at the indicated location, will succeed in making the program display a button spanning the whole window area?()   import java.awt.*;   public class Q1e65 {   public static void main(String args[]) {   Window win = new Frame();   Button but = new Button("button");   // insert code fragment here  win.setSize(200, 200);   win.setVisible(true);   }   }Awin.setLayout(new BorderLayout()); win.add(but);Bwin.setLayout(new GridLayout(1, 1)); win.add(but);Cwin.setLayout(new BorderLayout()); win.add(but, BorderLayout.CENTER);Dwin.add(but);Ewin.setLayout(new FlowLayout()); win.add(but);

问题 单选题10. public Object m() { 11. Object o = new Float(3.14F); 12. Object [] oa = new Object[1]; 13. oa[0] = o; 14. o = null; 15. return oa[0]; 16. } When is the Float object, created in line 11, eligible for garbage collection?()A  Just after line 13.B  Just after line 14.C  Never in this method.D  Just after line 15 (that is, as the method returns).

问题 单选题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 4B  line 6C  line 7D  line 8