网友您好, 请在下方输入框内输入要搜索的题目:

题目内容 (请给出正确答案)
单选题
public class Test {  public static void main(String[] args) {  int x = 0;  assert (x > 0): “assertion failed”;  System.out.println(“finished”);  }  }  What is the result?()
A

 finished

B

 Compilation fails.

C

 An AssertionError is thrown.

D

 An AssertionError is thrown and finished is output.


参考答案

参考解析
解析: This question is a bit tricky because it lacks the following information: It should include a statement that says whether or not assertions are enabled. If they are indeed enabled, the 
correction answer is C. but if they are not, the correct answer is A. Assertions are not enabled by default so if the question is not changed, the most logical answer is A.
更多 “单选题public class Test {  public static void main(String[] args) {  int x = 0;  assert (x  0): “assertion failed”;  System.out.println(“finished”);  }  }  What is the result?()A  finishedB  Compilation fails.C  An AssertionError is thrown.D  An AssertionError is thrown and finished is output.” 相关考题
考题 多选题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     }    }Ai = m;Bi = b;Ci = p.a;Di = p.change(30);Ei = t.b.

考题 单选题switch (i) {  default:   System.out.printIn(“Hello”);   }  What is the acceptable type for the variable i?()A  ByteB  LongC  FloatD  DoubleE  ObjectF  A and BG  C and D

考题 多选题Given the following code fragment:     public void create() {     Vector myVect;     myVect = new Vector();      }  Which of the following statements are true?()AThe declaration on line 2 does not allocate memory space for the variable myVect.BThe declaration on line 2 allocates memory space for a reference to a Vector object.CThe statement on line 2 creates an object of class Vector.DThe statement on line 3 creates an object of class Vector.EThe statement on line 3 allocates memory space for an object of class Vector.

考题 单选题System.out.println(Math.sqrt(-4D));  What is the result?()A  –2B  NaNC  InfinityD  Compilation fails.E  An exception is thrown at runtime.

考题 单选题1. public class X implements Runnable(  2. private int x;  3. private int y;  4.    5. public static void main(String[]args)  6. X that = new X();  7. (new Thread(that)).start();  8. (new Thread(that)).start();  9. )  10.    11. public void run()  (  12. for (;;)  (  13. x++; 14. y++;  15. System.out.printIn(“x=” + x + “, y = ” + y);  16.     ) 17. ) What is the result?()A  Errors at lines 7 and 8 cause compilation to fail.B  The program prints pairs of values for x and y that might not always be the same on the same line (for example, “x=2, y=1”).C  The program prints pairs of values for x and y that are always the same on the same line (for example, “x=1, y=1”. In addition, each value appears twice (for example, “x=1, y=1” followed by “x=1, y=1”).D  The program prints pairs of values for x and y that are always the same on the same line (for example, “x=1, y=1”. In addition, each value appears only for once (for example, “x=1, y=1” followed by “x=2, y=2”).

考题 单选题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{}

考题 单选题Which statement about static inner classes is true? ()A  An anonymous class can be declared as static.B  A static inner class cannot be a static member of the outer class.C  A static inner class does not require an instance of the enclosing class.D  Instance members of a static inner class can be referenced using the class name of the static inner class.

考题 多选题Which two are benefits of fully encapsulating a class?()APerformance of class methods is improved.BImplementation details of the class are hidden.CAccess modifiers can be omitted on class data members.DCode that uses the encapsulation class can access data members directly.EInternal operation of the class can be modified without impacting clients of that class.

考题 单选题interface foo {   int k = 0;   }    public class test implements Foo (   public static void main(String args) (    int i;   Test test = new test ();   i= test.k;   i= Test.k;   i= Foo.k;   )   )   What is the result? ()A  Compilation succeeds.B  An error at line 2 causes compilation to fail.C  An error at line 9 causes compilation to fail.D  An error at line 10 causes compilation to fail.E  An error at line 11 causes compilation to fail.

考题 单选题class A {   public String toString () {   return “4”;   }   }   class B extends A {   8. public String toString () {   return super.toString() + “3”;   }   }   public class Test {   public static void main(Stringargs) {   System.out.printIn(new B());   }   }   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.