Java OCA OCP Practice Question 2633

Question

Given:

3. class Employee {  
4.   private String name;  
5.   void setName(String n) { name = n; }  
6.   String getName() { return name; }  
7. }  //from  www.java  2 s  . co m
8. interface Printable {  
9.   void print();  
10. }  
11. public class Main implements Printable {  
12.   public void print() { ; }  
13.   public static void main(String[] args) {  
14.     Employee e = new Employee();  
15.     e.setName("bob");     
16.     System.out.print(e.getName());  
17.   } 
18. } 

Which are true? (Choose all that apply.)

  • A. Main is-a Employee.
  • B. Main is-a Printable.
  • C. Main has-a Employee.
  • D. Main has-a Printable.
  • E. The code is loosely coupled.
  • F. The Employee class is well encapsulated.


B, E, and F are correct statements about the code.

Note

A and C are incorrect because the Main class "uses" the Employee class, but Main isn't in Employee's class hierarchy, and Main doesn't "have" an Employee as part of its state.

D is similarly incorrect because Main doesn't "have" a Printable as part of its state.




PreviousNext

Related