多选题 Which of the following statements about variables and their scopes are true? ()
Instance variables are member variables of a class.
Instance variables are declared with the static keyword.
Local variables defined inside a method are created when the method is executed.
Local variables must be initialized before they are used.
单选题 What is the result?()
Compilation fails due to an error in line 23.
Compilation fails due to an error in line 29.
A ClassCastException occurs in line 29.
A ClassCastException occurs in line 31.
The value of all four objects prints in natural order.
多选题 Which two code fragments correctly create and initialize a static array of int elements?()
static final int[] a = { 100,200 };
static final int[] a; static { a=new int[2]; a[0]=100; a[1]=200; }
static final int[] a = new int[2] { 100,200 };
static final int[] a; static void init() { a = new int[3]; a[0]=100; a[1]=200; }
单选题 Which line of code marks the earliest point that an object referenced by intObj becomes a candidate for garbage collection?()
Line 16
Line 17
Line 18
Line 19
The object is NOT a candidate for garbage collection.
单选题 What is the result?()
Canada
null Canada
Canada null
Canada Canada
Compilation fails due to an error on line 26.
Compilation fails due to an error on line 29.
多选题 package sun.scjp; public enum Color { RED, GREEN, BLUE } package sun.beta; // insert code here public class Beta { Color g = GREEN; public static void main( String[] argv) { System.out.println( GREEN); } } The class Beta and the enum Color are in different packages. Which two code fragments, inserted individually at line 2 of the Beta declaration, will allow this code to compile?()
import sun.scjp.Color.*;
import static sun.scjp.Color.*;
import sun.scjp.Color; import static sun.scjp.Color.*;
import sun.scjp.*; import static sun.scjp.Color.*;
import sun.scjp.Color; import static sun.scjp.Color.GREEN;
单选题 Which code, inserted at line 14, allows the Sprite class to compile?()
Direction d = NORTH;
Nav.Direction d = NORTH;
Direction d = Direction.NORTH;
Nav.Direction d = Nav.Direction.NORTH;
多选题 Which three statements are true?()
The default constructor initializes method variables.
The default constructor has the same access as its class.
The default constructor invoked the no-arg constructor of the superclass.
If a class lacks a no-arg constructor, the compiler always creates a default constructor.
The compiler creates a default constructor only when there are no other constructors for the class.
多选题 10. interface Foo { 11. int bar(); 12. } 13. 14. public class Beta { 15. 16. class A implements Foo { 17. public int bar() { return 1; } 18. } 19. 20. public int fubar( Foo foo) { return foo.bar(); } 21. 22. public void testFoo() { 23. 24. class A implements Foo { 25. public int bar() { return 2; } 26. } 27. 28. System.out.println( fubar( new A())); 29. } 30. 31. public static void main( String[] argv) { 32. new Beta().testFoo(); 33. } 34. } Which three statements are true?()
Compilation fails.
The code compiles and the output is 2.
If lines 16, 17 and 18 were removed, compilation would fail.
If lines 24, 25 and 26 were removed, compilation would fail.
If lines 16, 17 and 18 were removed, the code would compile and the output would be 2.
If lines 24, 25 and 26 were removed, the code would compile and the output would be 1.
多选题 1. class TestA { 2. TestB b; 3. TestA() { 4. b = new TestB(this); 5. } 6. } 7. class TestB { 8. TestA a; 9. TestB(TestA a) { 10. this.a = a; 11. } 12. } 13. class TestAll { 14. public static void main (String args[]) { 15. new TestAll().makeThings(); 16. // ...code continues on 17. } 18. void makeThings() { 19. TestA test = new TestA(); 20. } 21. } Which two statements are true after line 15, before main completes?()
Line 15 causes a stack overflow.
An exception is thrown at runtime.
The object referenced by a is eligible for garbage collection.
The object referenced by b is eligible for garbage collection.
The object referenced by a is not eligible for garbage collection.
The object referenced by b is not eligible for garbage collection.