10. class Line {  11. public static class Point { }  12. }  13.  14. class Triangle {  15. // insert code here  16. }  Which code, inserted at line 15, creates an instance of the Point class defined in Line?() A、 Point p = new Point();B、 Line.Point p = n

题目

10. class Line {  11. public static class Point { }  12. }  13.  14. class Triangle {  15. // insert code here  16. }  Which code, inserted at line 15, creates an instance of the Point class defined in Line?() 

  • A、 Point p = new Point();
  • B、 Line.Point p = new Line.Point();
  • C、 The Point class cannot be instatiated at line 15.
  • D、 Line 1 = new Line() ; 1.Point p = new 1.Point();

相似考题
更多“10. class Line {”相关问题
  • 第1题:

    1. public class Outer{  2. public void someOuterMethod() {  3. // Line 3  4. }  5. public class Inner{}  6. public static void main( String[]argv ) {  7. Outer o = new Outer();  8. // Line 8  9. }  10. }  Which instantiates an instance of Inner?()  

    • A、 new Inner(); // At line 3
    • B、 new Inner(); // At line 8
    • C、 new o.Inner(); // At line 8
    • D、 new Outer.Inner(); // At line 8

    正确答案:A

  • 第2题:

    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.

    正确答案:B

  • 第3题:

    1. public class X {  2. public object m ()  {  3. object o = new float (3.14F);  4. object [] oa = new object [1]; 5. oa[0]= o;  6. o = null;  7. oa[0] = null;  10. return o;  9. }  10. }  When is the float object created in line 3, eligible for garbage collection?()  

    • A、 Just after line 5.
    • B、 Just after line 6.
    • C、 Just after line 7.
    • D、 Just after line 8(that is, as the method returns).

    正确答案:C

  • 第4题:

    1. public class A {  2.  3. private int counter = 0;  4.  5. public static int getInstanceCount() {  6. return counter;  7. }  8.  9. public A() {  10. counter++;  11. }  12.  13. }  Given this code from Class B:  25.A a1 =new A();  26. A a2 =new A();  27. A a3 =new A();  28. System.out.printIn(A.getInstanceCount() ); What is the result?() 

    • A、 Compilation of class A fails.
    • B、 Line 28 prints the value 3 to System.out.
    • C、 Line 28 prints the value 1 to System.out.
    • D、 A runtime error occurs when line 25 executes.
    • E、 Compilation fails because of an error on line 28.

    正确答案:A

  • 第5题:

    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

  • 第6题:

    单选题
    1. class A {  2. public String toString ()  {  3. return “4”;  4. }  5. }  6. class B extends A {  7. public String toString ()   {  8. return super.toString()  + “3”;  9. }  10. }  11. public class Test {  12.   public static void main(String[]args)  {  13.      System.out.printIn(new B());  14.      }  15. }    What is the result?()
    A

     Compilation succeeds and 4 is printed.

    B

     Compilation succeeds and 43 is printed.

    C

     An error on line 9 causes compilation to fail.

    D

     An error on line 14 causes compilation to fail.

    E

     Compilation succeeds but an exception is thrown at line 9.


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

  • 第7题:

    多选题
    Given:   10. class One {   11. void foo() { }   12. }   13. class Two extends One {   14. //insert method here   15. }   Which three methods, inserted individually at line 14, will correctly complete class Two?()
    A

    public void foo() { /* more code here */ }

    B

    private void foo() { /* more code here */ }

    C

    protected void foo() { /* more code here */ }

    D

    int foo() { /* more code here */ }

    E

    void foo() { /* more code here */ }


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

  • 第8题:

    单选题
    1. public class Outer{  2. public void someOuterMethod() {  3. // Line 3  4. }  5. public class Inner{}  6. public static void main( String[]argv ) {  7. Outer o = new Outer();  8. // Line 8  9. }  10. }  Which instantiates an instance of Inner?()
    A

     new Inner(); // At line 3

    B

     new Inner(); // At line 8

    C

     new o.Inner(); // At line 8

    D

     new Outer.Inner(); // At line 8


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

  • 第9题:

    单选题
    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
    解析: 暂无解析

  • 第10题:

    单选题
    1. class SuperClass {  2. public a geta() {  3. return new a();  4. }  5. }  6. class SubClass extends SuperClass {  7. public b geta() {  8. return new b();  9. }  10. }  Which is true?()
    A

     Compilation will succeed if a extends b.

    B

     Compilation will succeed if b extends a.

    C

     Compilation will always fail because of an error in line 7.

    D

     Compilation will always fail because of an error in line 8.


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

  • 第11题:

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


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

  • 第12题:

    单选题
    1. class Bar { }  1. class Test {  2. Bar doBar() {  3. Bar b = new Bar();  4. return b;  5. }  6. public static void main (String args[]) {  7. Test t = new Test();  8. Bar newBar = t.doBar();  9. System.out.println(“newBar”);  10. newBar = new Bar();  11. System.out.println(“finishing”);  12. }  13. } At what point is the Bar object, created on line 3, eligible for garbage collection?()
    A

     After line 8.

    B

     After line 10.

    C

     After line 4, when doBar() completes.

    D

     After line 11, when main() completes.


    正确答案: B
    解析: The correct answer is B. When a local object is returned, it is not yet available for garbage collection. For this reason, the object is only available for garbage collecting at line 10, where the only remaining reference to the object is replaced with an other object.

  • 第13题:

    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

  • 第14题:

    1. public class A {  2. public void doit() {  3. }  4. public String doit() {  5. return “a”;  6. }  7. public double doit(int x) {  8. return 1.0;  9. }  10.}  What is the result?() 

    • A、 An exception is thrown at runtime.
    • B、 Compilation fails because of an error in line 7.
    • C、 Compilation fails because of an error in line 4.
    • D、 Compilation succeeds and no runtime errors with class A occur.

    正确答案:C

  • 第15题:

    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;  8.System.out.printIn(foo. i); 9. }  10.}   What is the result?()  

    • A、 Compilation will fail.
    • B、 Compilation will succeed and the program will print “3”
    • C、 Compilation will succeed but the program will throw a ClassCastException at line 6.
    • D、 Compilation will succeed but the program will throw a ClassCastException at line 7.

    正确答案:B

  • 第16题:

    1. class Bar { }  1. class Test {  2. Bar doBar() {  3. Bar b = new Bar();  4. return b;  5. }  6. public static void main (String args[]) {  7. Test t = new Test();  8. Bar newBar = t.doBar();  9. System.out.println(“newBar”);  10. newBar = new Bar();  11. System.out.println(“finishing”);  12. }  13. } At what point is the Bar object, created on line 3, eligible for garbage collection?()  

    • A、 After line 8.
    • B、 After line 10.
    • C、 After line 4, when doBar() completes.
    • D、 After line 11, when main() completes.

    正确答案:B

  • 第17题:

    单选题
    1. public class X {  2. public object m ()  {  3. object o = new float (3.14F);  4. object [] oa = new object [1]; 5. oa[0]= o;  6. o = null;  7. oa[0] = null;  10. return o;  9. }  10. }  When is the float object created in line 3, eligible for garbage collection?()
    A

     Just after line 5.

    B

     Just after line 6.

    C

     Just after line 7.

    D

     Just after line 8(that is, as the method returns).


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

  • 第18题:

    多选题
    Click the Exhibit button.   Given: Which two statements are true if a NullPointerException is thrown on line 3 of class C?()
    A

    The application will crash.

    B

    The code on line 29 will be executed.

    C

    The code on line 5 of class A will execute.

    D

    The exception will be propagated back to line 27.

    E

    The code on line 5 of class B will execute.


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

  • 第19题:

    单选题
    1. public class A {  2.  3. private int counter = 0;  4.  5. public static int getInstanceCount() {  6. return counter;  7. }  8.  9. public A() {  10. counter++;  11. }  12.  13. }  Given this code from Class B:  25.A a1 =new A();  26. A a2 =new A();  27. A a3 =new A();  28. System.out.printIn(A.getInstanceCount() ); What is the result?()
    A

     Compilation of class A fails.

    B

     Line 28 prints the value 3 to System.out.

    C

     Line 28 prints the value 1 to System.out.

    D

     A runtime error occurs when line 25 executes.

    E

     Compilation fails because of an error on line 28.


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

  • 第20题:

    单选题
    10. class Line {  11. public static class Point { }  12. }  13.  14. class Triangle {  15. // insert code here  16. }  Which code, inserted at line 15, creates an instance of the Point class defined in Line?()
    A

     Point p = new Point();

    B

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

    C

     The Point class cannot be instatiated at line 15.

    D

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


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

  • 第21题:

    单选题
    Given: Which code, inserted at line 15, creates an instance of the Point class defined in Line?()
    A

    Point p = new Point();

    B

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

    C

    The Point class cannot be instatiated at line 15.

    D

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


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

  • 第22题:

    单选题
    1. public class GC {  2. private Object o;  3. private void doSomethingElse(Object obj) { o = obj; }  4. public void doSomething() {  5. Object o = new Object();  6. doSomethingElse(o);  7. o = new Object();  8. doSomethingElse(null);  9.o=null;  10. }  11. }  When the doSomething method is called, after which line does the Object created in line 5 become available for garbage collection?()
    A

     Line 5

    B

     Line 6

    C

     Line 7

    D

     Line 8

    E

     Line 9

    F

     Line 10


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

  • 第23题:

    单选题
    10. class Nav{  11. public enum Direction { NORTH, SOUTH, EAST, WEST }  12. }  13. public class Sprite{  14. // insert code here  15. }  Which code, inserted at line 14, allows the Sprite class to compile?()
    A

     Direction d = NORTH;

    B

     Nav.Direction d = NORTH;

    C

     Direction d = Direction.NORTH;

    D

     Nav.Direction d = Nav.Direction.NORTH;


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