单选题10. public class ClassA {  11. public void count(int i) {  12. count(++i);  13. }  14. }  And:  20. ClassA a = new ClassA();  21. a.count(3);  Which exception or error should be thrown by the virtual machine?()A  StackOverflowErrorB  NullPointerExcepti

题目
单选题
10. public class ClassA {  11. public void count(int i) {  12. count(++i);  13. }  14. }  And:  20. ClassA a = new ClassA();  21. a.count(3);  Which exception or error should be thrown by the virtual machine?()
A

 StackOverflowError

B

 NullPointerException

C

 NumberFormatException

D

 IllegalArgumentException

E

 ExceptionlnlnitializerError

如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

3下面程序段的输出结果为( )。package test;public class ClassA{ int x=20; static int y=6; public static void main(String args[]) { ClassB b=new ClassB(); b.go(10); System.out.println("x="+b.x); }}class ClassB{ int x; void go(int y) { ClassA a=new ClassA(); x=a.y; }}

A.x=10

B.x=20

C.x=6

D.编译不通过


正确答案:C

第2题:

11. class Converter {  12. public static void main(String[] args) {  13. Integer i = args[0];  14. int j = 12;  15. System.out.println(”It is “ + (j==i) + “that j==i.”);  16. }  17. }  What is the result when the programmer attempts to compile the code and run it with the command java Converter 12?() 

  • A、 It is true that j==i.
  • B、 It is false that j==i.
  • C、 An exception is thrown at runtime.
  • D、 Compilation fails because of an error in line 13.

正确答案:D

第3题:

下面程序段的输出结果为 package test; public class ClassA { int x=20; static int y=6; public static void main(String args[]) { ClassB b=new ClassB(); b.go(10); System.out.println("x="+b.x); } } class ClassB { int x; void go(int y) { ClassA a=new ClassA(); x=a.y; } }

A.x=10

B.x=20

C.x=6

D.编译不通过


正确答案:C
解析:本题考查在Java中静态变量(类变量)的用法。在题目程序段中生成了一个static int y=6类变量,在ClassA中调用的 b.go(10),只不过是在ClassB中的一个局部变量,通过调用ClassB中的go方法可以生成一个ClassA对象,并给这个新生成的对象赋以ClassA中的类变量y的值。从main()方法作为入口执行程序,首先生成一个ClassB的对象,然后b.go(10)会调用 ClassA,会给x和y赋值,x=a.y后,x值为6,再返回去执行System.out.println("x="/b.x)语句,输出为x=6,可见,正确答案为选项C。

第4题:

1. class A implements runable (   2. int i;   3. public void run () (   4. try (   5. thread.sleep(5000);   6. i= 10;   7. ) catch(InterruptedException e) {}   8. )   9. )   10.   11. public class Test {   12. public static void main (string args) (   13. try (   14. A a = new A ();   15. Thread t = new Thread (a);  16. t.start();  17.   18. int j= a.i;   19.   20. ) catch (Exception e) {}   21. )   22. )   Which statement al line 17 will ensure that j=10 at line 19?()

  • A、 a.wait();
  • B、 t.wait();
  • C、 t.join();
  • D、 t.yield();
  • E、 t.notify();
  • F、 a.notify();
  • G、 t.interrupt();

正确答案:C

第5题:

class ClassA {  public int numberOfinstances;  protected ClassA(int numberOfinstances) {  this.numberOflnstances = numberOfinstances;  }  }  public class ExtendedA extends ClassA {  private ExtendedA(int numberOfinstances) {  super(numberOflnstances);  }  public static void main(String[] args) {  ExtendedA ext = new ExtendedA(420);  System.out.print(ext.numberOflnstances);  }  }  Which is true?() 

  • A、 420 is the output.
  • B、 An exception is thrown at runtime.
  • C、 All constructors must be declared public.
  • D、 Constructors CANNOT use the private modifier.
  • E、 Constructors CANNOT use the protected modifier.

正确答案:A

第6题:

10. public class ClassA {  11. public void count(int i) {  12. count(++i);  13. }  14. }  And:  20. ClassA a = new ClassA();  21. a.count(3);  Which exception or error should be thrown by the virtual machine?() 

  • A、 StackOverflowError
  • B、 NullPointerException
  • C、 NumberFormatException
  • D、 IllegalArgumentException
  • E、 ExceptionlnlnitializerError

正确答案:A

第7题:

1. public class Test { 2. public static String output =””; 3.  4. public static void foo(int i) { 5. try { 6. if(i==1) { 7. throw new Exception(); 8. } 9. output += “1”; 10. } 11. catch(Exception e) { 12. output += “2”; 13. return; 14. } 15. finally { 16. output += “3”;17. } 18. output += “4”; 19. } 20.  21. public static void main(String args[]) { 22. foo(0); 23. foo(1); 24.  25. }26. } What is the value of the variable output at line 23?()


正确答案:13423

第8题:

下面程序段的输出结果为( )。 package test; public class ClassA { int x=20: static int y=6; public static void main(String args[]) { ClassB b=new ClassB; go(10); System.out.println("x="+b.x); } } class ClassB { int X; void go(int y) { ClassA a=new ClassA; x=a.Y ; } }

A.x=10

B.x=20

C.x=6

D.编译不通过


正确答案:C
C。【解析】本题考查在Java中静态变量(类变量)的用法。在题目程序段中生成了一个staticinty=6类变量,在ClassA中调用的b.go(10),只不过是在ClassB中的一个局部变量,通过调用ClassB中的90方法可以生成一个ClassA对象,并给这个新生成的对象赋以ClassA中的类变量Y的值。从main方法作为入口执行程序,首先生成一个ClassB的对象,然后b.go(10)会调用ClassA,会给X和Y赋值,X=a.Y后,X值为6,再返回去执行System.out.println("x="+b.x)语句,输出为x=6,可见,正确答案为选项C。

第9题:

11.classA {  12. public void process() { System.out.print(”A “); } }  13. class B extends A {  14. public void process() throws RuntimeException {  15. super.process();  16. if (true) throw new RuntimeException();  17. System.out.print(“B”); }}  18. public static void main(String[] args) {  19. try { ((A)new B()).process(); }  20. catch (Exception e) { System.out.print(”Exception “); }  21. }  What is the result?() 

  • A、 Exception
  • B、 A Exception
  • C、 A Exception B
  • D、 A B Exception
  • E、 Compilation fails because of an error in line 14.
  • F、 Compilation fails because of an error in line 19.

正确答案:B

第10题:

10. class Inner {  11. private int x;  12. public void setX( int x) { this.x = x; }  13. public int getX() { return x; }  14. }  15.  16. class Outer {  17. private Inner y;  18. public void setY( Inner y) { this.y = y; }  19. public Inner getY() { return y; }  20. }  21.  22. public class Gamma {  23. public static void main( String[] args) { 24. Outer o = new Outer(); 25. Inner i = new Inner();  26.int n=10;  27. i.setX(n);  28. o.setY(i);  29. // insert code here  30. System.out.println( o.getY().getX());  31. }  32. }  Which three code fragments, added individually at line 29, produce the output 100?()

  • A、 n = 100;
  • B、 i.setX( 100);
  • C、 o.getY().setX( 100);
  • D、 i = new Inner(); i.setX( 100);
  • E、 o.setY( i); i = new Inner(); i.setX( 100);
  • F、 i = new Inner(); i.setX( 100); o.setY( i);

正确答案:B,C,F

更多相关问题