单项选择题

public class Test { 
public enum Dogs {collie, harrier}; 
public static void main(String [] args) { 
Dogs myDog = Dogs.collie; 
switch (myDog) { 
case collie: 
System.out.print(”collie “);
case harrier: 
System.out.print(”harrier “); 
} 
} 
} 
What is the result?() 

A. collie
B. harrier
C. Compilation fails.
D. collie harrier
E. An exception is thrown at runtime.


您可能感兴趣的试卷

你可能感兴趣的试题

3.单项选择题

public class Plant { 
private String name; 
public Plant(String name) { this.name = name; } 
public String getName() { return name; } 
} 
public class Tree extends Plant { 
public void growFruit() { } 
public void dropLeaves() { } 
} 
Which is true?() 

A. The code will compile without changes.
B. The code will compile if public Tree() { Plant(); } is added to the Tree class.
C. The code will compile if public Plant() { Tree(); } is added to the Plant class.
D. The code will compile if public Plant() { this(”fern”); } is added to the Plant class.
E. The code will compile if public Plant() { Plant(”fern”); } is added to the Plant class.

7.单项选择题

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();

8.单项选择题

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.

9.单项选择题

1. public class A { 
2. public String doit(int x, int y) { 
3. return “a”; 
4. } 
5. 
6. public String doit(int... vals) { 
7. return “b”; 
8. }
9. } 
Given: 
25. A a=new A(); 
26. System.out.println(a.doit(4, 5)); 
What is the result?() 

A. Line 26 prints “a” to System.out.
B. Line 26 prints „b” to System.out.
C. An exception is thrown at line 26 at runtime.
D. Compilation of class A will fail due to an error in line 6.