单项选择题

11. class Person { 
12. String name = “No name‟; 
13. public Person(String nm) { name = nm; } 
14. } 
15. 
16. class Employee extends Person { 
17. String emplD = “0000”; 
18. public Employee(String id) { empID = id; } 
19. } 
20. 
21. public class EmployeeTest { 
22. public static void main(String[] args) { 
23. Employee e = new Employee(”4321”); 
24. System.out.println(e.empID); 
25. } 
26. } 
What is the result?() 

A. 4321
B. 0000
C. An exception is thrown at runtime.
D. Compilation fails because of an error in line 18.


您可能感兴趣的试卷

你可能感兴趣的试题

3.单项选择题

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

4.单项选择题

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.

5.单项选择题

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.

7.多项选择题

class One { 
void foo() {} 
} 
class Two extends One { 
 //insert method here 
} 
Which three methods, inserted individually at line 14, will correctly complete class Two?()

A. int foo() { /* more code here */ }
B. void foo() { /* more code here */ }
C. public void foo() { /* more code here */ }
D. private void foo() { /* more code here */ }
E. protected void foo() { /* more code here */ }

8.多项选择题

class One { 
 public One foo() { return this; } 
} 
class Two extends One { 
public One foo() { return this; } 
} 
class Three extends Two { 
 // insert method here 
} 
Which two methods, inserted individually, correctly complete the Three class?()

A. public void foo() { }
B. public int foo() { return 3; }
C. public Two foo() { return this; }
D. public One foo() { return this; }
E. public Object foo() { return this; }

9.多项选择题

A JavaBeans component has the following field: 
11. private boolean enabled; 
Which two pairs of method declarations follow the JavaBeans standard for accessing this field?()

A. public void setEnabled( boolean enabled) public boolean getEnabled()
B. public void setEnabled( boolean enabled) public void isEnabled()
C. public void setEnabled( boolean enabled) public boolean isEnabled()
D. public boolean setEnabled( boolean enabled) public boolean getEnabled()