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?()
第1题:
11. public static void main(String[] args) { 12. Object obj =new int[] { 1,2,3 }; 13. int[] someArray = (int[])obj; 14. for (int i: someArray) System.out.print(i +“ “) 15. } What is the result? ()
第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?()
第3题:
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?()
第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?()
第5题:
10. public class Hello { 11. String title; 12. int value; 13. public Hello() { 14. title += “ World”; 15. } 16. public Hello(int value) { 17. this.value = value; 18. title = “Hello”; 19. Hello(); 20. } 21. } and: 30. Hello c = new Hello(5); 31. System.out.println(c.title); What is the result?()
第6题:
10. public class MyClass { 11. 12. public Integer startingI; 13. public void methodA() { 14. Integer i = new Integer(25); 15. startingI = i; 16. methodB(i); 17. } 18. private void methodB(Integer i2) { 19. i2 = i2.intValue(); 20. 21. } 22. } If methodA is invoked, which two are true at line 20?()
第7题:
11.classa { 12. public void process() { System.out.print(”a,”); } } 13. class b extends a { 14. public void process() throws IOException { 15. super.process(); 16. System.out.print(”b,”); 17. throw new IOException(); 18. } } 19. public static void main(String[] args) { 20. try { new b().process(); } 21. catch (IOException e) { System.out.println(”Exception”); } } What is the result?()
第8题:
Given: 11. static class A { 12. void process() throws Exception { throw new Exception(); } 13. } 14. static class B extends A { 15. void process() { System.out.println("B "); } 16. } 17. public static void main(String[] args) { 18. A a = new B(); 19. a.process(); 20. } What is the result? ()
第9题:
n = 100;
i.setX( 100);
o.getY().setX( 100);
i = new Inner(); i.setX( 100);
o.setY( i); i = new Inner(); i.setX( 100);
i = new Inner(); i.setX( 100); o.setY( i);
第10题:
Compilation fails because of an error in line 19.
An exception is thrown at runtime.
B
Compilation fails because of an error in line 18.
Compilation fails because of an error in line 15.
The code runs with no output.
第11题:
Compilation fails because of an error in line 13.
A ClassCastException is thrown at runtime.
1 2 3
Compilation fails because of an error in line 14.
Compilation fails because of an error in line 12.
第12题:
i2 == startingI returns true.
i2 == startingI returns false.
i2.equals(startingI) returns true.
i2.equals(startingI) returns false.
第13题:
10. interface Foo { int bar(); } 11. public class Sprite { 12. public int fubar( Foo foo) { return foo.bar(); } 13. public void testFoo() { 14. fubar( 15. // insert code here 16.); 17. } 18. } Which code, inserted at line 15, allows the class Sprite to compile?()
第14题:
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?()
第15题:
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?()
第16题:
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?()
第17题:
10. public class ClassA { 11. public void methodA() { 12. ClassB classB = new ClassB(); 13. classB.getValue(); 14. } 15. } And: 20. class ClassB { 21. public ClassC classC; 22. 23. public String getValue() { 24. return classC.getValue(); 25. } 26. } And: 30. class ClassC { 31. public String value; 32. 33. public String getValue() { 34. value = “ClassB”; 35. return value; 36. } 37. } Given: ClassA a = new ClassA(); a.methodA(); What is the result?()
第18题:
public class ClassA { public int getValue() { int value=0; boolean setting = true; String title=”Hello”; (value || (setting && title == “Hello”)) { return 1; } (value == 1 & title.equals(”Hello”)) { return 2; } } } And: ClassA a = new ClassA(); a.getValue(); What is the result?()
第19题:
11. static classA { 12. void process() throws Exception { throw new Exception(); } 13. } 14. static class B extends A { 15. void process() { System.out.println(”B “); } 16. } 17. public static void main(String[] args) { 18.A a=new B(); 19. a.process(); 20.} What is the result?()
第20题:
B
The code runs with no output.
An exception is thrown at runtime.
Compilation fails because of an error in line 15.
Compilation fails because of an error in line 18.
Compilation fails because of an error in line 19.
第21题:
1 2 3
Compilation fails because of an error in line 12.
Compilation fails because of an error in line 13.
Compilation fails because of an error in line 14.
A ClassCastException is thrown at runtime.
第22题:
StackOverflowError
NullPointerException
NumberFormatException
IllegalArgumentException
ExceptionlnlnitializerError
第23题:
1
2
Compilation fails.
The code runs with no output.
An exception is thrown at runtime.