单选题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?()AT

题目
单选题
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.


相似考题
更多“单选题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 ”相关问题
  • 第1题:

    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.

    正确答案:B

  • 第2题:

    public class Team extends java.util.LinkedList {  public void addPlayer(Player p) {  add(p);  }  public void compete(Team opponent) { /* more code here */ }  }  class Player { /* more code here */ }  Which two are true?()

    • A、 This code will compile.
    • B、 This code demonstrates proper design of an is-a relationship.
    • C、 This code demonstrates proper design of a has-a relationship.
    • D、 A Java programmer using the Team class could remove Player objects from a Team object.

    正确答案:A,D

  • 第3题:

    //point X    public class foo (   public static void main (Stringargs) throws Exception {   printWriter out = new PrintWriter (new )  java.io.outputStreamWriter (System.out), true;   out.printIn(“Hello”);    }   )   Which statement at PointX on line 1 allows this code to compile and run?()

    • A、 Import java.io.PrintWriter;
    • B、 Include java.io.PrintWriter;
    • C、 Import java.io.OutputStreamWriter;
    • D、 Include java.io.OutputStreamWriter;
    • E、 No statement is needed.

    正确答案:A

  • 第4题:

    public class TestA{   public void methodA()  throws IOException{   //……   }   }   public class TestB extends TestA{   public void methodA()  throws EOFException{   //……   }   }   public class TestC extends TestA{   public void methodA()  throws Exception{   //……   }   }   当编译类TestC的时候,结果是哪项?() 

    • A、 正常
    • B、 编译错误
    • C、 运行错误
    • D、 以上都不对

    正确答案:B

  • 第5题:

    // Point X  public class foo {  public static void main(String[] args) throws Exception {  jave.io.PrintWriter out = new jave.io.PrintWriter(  new jave.io.OutputStreamWriter(System.out), true); out.println(“Hello”); }  }   Which statement at Point X on line 1 is required to allow this code to compile?()  

    • A、 No statement is required.
    • B、 import jave.io.*;
    • C、 include java.io.*;
    • D、 import jave.io.PrintWriter;
    • E、 include java.io.PrintWriter;

    正确答案:A

  • 第6题:

    public abstract class Shape {  private int x;  private int y;  public abstract void draw();  public void setAnchor(int x, int y) {  this.x = x;  this.y = y;  }  }  Which two classes use the Shape class correctly?()

    • A、 public class Circle implements Shape { private int radius; }
    • B、 public abstract class Circle extends Shape { private int radius; }
    • C、 public class Circle extends Shape { private int radius; public void draw(); }
    • D、 public abstract class Circle implements Shape { private int radius; public void draw(); }
    • E、 public class Circle extends Shape { private int radius;public void draw() {/* code here */} }
    • F、 public abstract class Circle implements Shape { private int radius;public void draw() { / code here */ } }

    正确答案:B,E

  • 第7题:

    单选题
    1. public class Exception Test {  2. class TestException extends Exception {}  3. public void runTest() throws TestException {}  4. public void test() /* Point X */ {  5. runTest();  6. }  7. }  At Point X on line 4, which code is necessary to make the code compile?()
    A

     No code is necessary.

    B

     throws Exception

    C

     catch ( Exception e )

    D

     throws RuntimeException

    E

     catch ( TestException e)


    正确答案: E
    解析: 暂无解析

  • 第8题:

    单选题
    public class Plant {  private String name;  public Plant(String name) { this.name = name; }  public String getName() { return name; }  }  public class Tree extends Plant {  public void growFruit() { }  public void dropLeaves() { }  }  Which is true?()
    A

     The code will compile without changes.

    B

     The code will compile if public Tree() { Plant(); } is added to the Tree class.

    C

     The code will compile if public Plant() { Tree(); } is added to the Plant class.

    D

     The code will compile if public Plant() { this(”fern”); } is added to the Plant class.

    E

     The code will compile if public Plant() { Plant(”fern”); } is added to the Plant class.


    正确答案: C
    解析: 暂无解析

  • 第9题:

    单选题
    public class TestA{   public void methodA()  throws IOException{   //……   }   }   public class TestB extends TestA{   public void methodA()  throws EOFException{   //……   }   }   public class TestC extends TestA{   public void methodA()  throws Exception{   //……   }   }   当编译类TestC的时候,结果是哪项?()
    A

     正常

    B

     编译错误

    C

     运行错误

    D

     以上都不对


    正确答案: B
    解析: 暂无解析

  • 第10题:

    多选题
    public class X {  public X aMethod() { return this;}  }  public class Y extends X {  }  Which two methods can be added to the definition of class Y?()
    A

    public void aMethod() {}

    B

    private void aMethod() {}

    C

    public void aMethod(String s) {}

    D

    private Y aMethod() { return null; }

    E

    public X aMethod() { return new Y(); }


    正确答案: D,B
    解析: 暂无解析

  • 第11题:

    多选题
    public abstract class Shape {  private int x;  private int y;  public abstract void draw();  public void setAnchor(int x, int y) {  this.x = x;  this.y = y;  }  }  Which two classes use the Shape class correctly?()
    A

    public class Circle implements Shape { private int radius; }

    B

    public abstract class Circle extends Shape { private int radius; }

    C

    public class Circle extends Shape { private int radius; public void draw(); }

    D

    public abstract class Circle implements Shape { private int radius; public void draw(); }

    E

    public class Circle extends Shape { private int radius;public void draw() {/* code here */} }

    F

    public abstract class Circle implements Shape { private int radius;public void draw() { / code here */ } }


    正确答案: B,F
    解析: 暂无解析

  • 第12题:

    单选题
    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.


    正确答案: A
    解析: 暂无解析

  • 第13题:

    public class X {  public X aMethod() { return this;}  }  public class Y extends X {  }  Which two methods can be added to the definition of class Y?()

    • A、 public void aMethod() {}
    • B、 private void aMethod() {}
    • C、 public void aMethod(String s) {}
    • D、 private Y aMethod() { return null; }
    • E、 public X aMethod() { return new Y(); }

    正确答案:C,E

  • 第14题:

    interface A { public int getValue() }  class B implements A {  public int getValue() { return 1; }  }  class C extends B {  // insert code here  }  Which three code fragments, inserted individually at line 15, make use of polymorphism?()

    • A、 public void add(C c) { c.getValue(); }
    • B、 public void add(B b) { b.getValue(); }
    • C、 public void add(A a) { a.getValue(); }
    • D、 public void add(A a, B b) { a.getValue(); }
    • E、 public void add(C c1, C c2) { c1.getValue(); }

    正确答案:B,C,D

  • 第15题:

    public class Plant {  private String name;  public Plant(String name) { this.name = name; }  public String getName() { return name; }  }  public class Tree extends Plant {  public void growFruit() { }  public void dropLeaves() { }  }  Which is true?() 

    • A、 The code will compile without changes.
    • B、 The code will compile if public Tree() { Plant(); } is added to the Tree class.
    • C、 The code will compile if public Plant() { Tree(); } is added to the Plant class.
    • D、 The code will compile if public Plant() { this(”fern”); } is added to the Plant class.
    • E、 The code will compile if public Plant() { Plant(”fern”); } is added to the Plant class.

    正确答案:D

  • 第16题:

    Given the following code, write a line of code that, when inserted at the indicated location, will make the overriding method in Extension invoke the overridden method in class Base on the current object.   class Base {   public void print( ) {   System.out.println("base");   }   }   class Extention extends Base {   public void print( ) {   System.out.println("extension");   // insert line of implementation here   }   }   public class Q294d {   public static void main(String args[]) {   Extention ext = new Extention( );   ext.print( );   }   }   Fill in a single line of implementation.()


    正确答案:super.print();

  • 第17题:

    Consider the following class:     class Test(int i) {     void test(int i) {  System.out.println(“I am an int.”); }    void test(String s) {   System.out.println(“I am a string.”);     }          public static void main(String args) {    Test t=new Test();     char ch=“y”;    t.test(ch);     }      }     Which of the statements below is true?()

    • 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 charargument.
    • 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

  • 第18题:

    10. class Line {  11. public class Point { public int x,y; }  12. public Point getPoint() { return new Point(); }  13. }  14. class Triangle {  15. public Triangle() {  16. // insert code here  17. }  18. }  Which code, inserted at line 16, correctly retrieves a local instance of a Point object?() 

    • A、 Point p = Line.getPoint();
    • B、 Line.Point p = Line.getPoint();
    • C、 Point p = (new Line()).getPoint();
    • D、 Line.Point p = (new Line()).getPoint();

    正确答案:D

  • 第19题:

    单选题
    // Point X  public class foo {  public static void main(String[] args) throws Exception {  jave.io.PrintWriter out = new jave.io.PrintWriter(  new jave.io.OutputStreamWriter(System.out), true); out.println(“Hello”); }  }   Which statement at Point X on line 1 is required to allow this code to compile?()
    A

     No statement is required.

    B

     import jave.io.*;

    C

     include java.io.*;

    D

     import jave.io.PrintWriter;

    E

     include java.io.PrintWriter;


    正确答案: B
    解析: 暂无解析

  • 第20题:

    单选题
    1. public class a {  2. public void method1() {  3. try {  4. B b=new b();  5. b.method2();  6. // more code here  7. } catch (TestException te) {  8. throw new RuntimeException(te);  9. }  10. }  11. }  1. public class b {  2. public void method2() throws TestException {  3. // more code here  4. }  5. }  1. public class TestException extends Exception {  2. }  Given:  31. public void method() {  32. A a=new a();  33. a.method1();  34. }  Which is true if a TestException is thrown on line 3 of class b?()
    A

     Line 33 must be called within a try block.

    B

     The exception thrown by method1 in class a is not required to be caught.

    C

     The method declared on line 31 must be declared to throw a RuntimeException.

    D

     On line 5 of class a, the call to method2 of class b does not need to be placed in a try/catch block.


    正确答案: A
    解析: 暂无解析

  • 第21题:

    单选题
    10. class Line {  11. public class Point { public int x,y; }  12. public Point getPoint() { return new Point(); }  13. }  14. class Triangle {  15. public Triangle() {  16. // insert code here  17. }  18. }  Which code, inserted at line 16, correctly retrieves a local instance of a Point object?()
    A

     Point p = Line.getPoint();

    B

     Line.Point p = Line.getPoint();

    C

     Point p = (new Line()).getPoint();

    D

     Line.Point p = (new Line()).getPoint();


    正确答案: A
    解析: 暂无解析

  • 第22题:

    单选题
    //point X    public class foo (   public static void main (Stringargs) throws Exception {   printWriter out = new PrintWriter (new )  java.io.outputStreamWriter (System.out), true;   out.printIn(“Hello”);    }   )   Which statement at PointX on line 1 allows this code to compile and run?()
    A

     Import java.io.PrintWriter;

    B

     Include java.io.PrintWriter;

    C

     Import java.io.OutputStreamWriter;

    D

     Include java.io.OutputStreamWriter;

    E

     No statement is needed.


    正确答案: C
    解析: 暂无解析

  • 第23题:

    单选题
    Consider the following class:     class Test(int i) {     void test(int i) {  System.out.println(“I am an int.”); }    void test(String s) {   System.out.println(“I am a string.”);     }          public static void main(String args) {    Test t=new Test();     char ch=“y”;    t.test(ch);     }      }     Which of the statements below is true?()
    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 charargument.

    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)方法。

  • 第24题:

    多选题
    Class TestException  1. public class TestException extends Exception {  2. } Class a:  1. public class a {  2.  3. public String sayHello(String name) throws TestException {  4.  5. if(name == null) {  6. throw new TestException();  7. }  8.  9. return “Hello “+ name;  10. }  11.  12. }  A programmer wants to use this code in an application: 45. A a=new A();  46. System.out.println(a.sayHello(”John”));  Which two are true?()
    A

    Class a will not compile.

    B

    Line 46 can throw the unchecked exception TestException.

    C

    Line 45 can throw the unchecked exception TestException.

    D

    Line 46 will compile if the enclosing method throws a TestException.

    E

    Line 46 will compile if enclosed in a try block, where TestException is caught.


    正确答案: D,E
    解析: 暂无解析