Java OCA OCP Practice Question 2947

Question

Given the design implied by this partially implemented class:

2. public class Main {  
3.   int size;  /*from  w  w  w .j a  v a  2 s.  co m*/
4.   void bark() { /* do barking */ }  
5.   int getSize() { return size; }  
6.   { size = 16; }  
7.   int getNetworkPrinterID() {   
8.     /* do lookup */   
9.     return 37;  
10.   }  
11.   void printMainShape(int printerID) { /* print Main stuff */ }  
12. } 

Which are true? (Choose all that apply.)

A.Compilation fails.
B.To improve cohesion, the size variable should be declared private.
C.To improve cohesion, the initialization block should be placed inside a constructor.
D.To improve cohesion, printMainShape() should be moved to a different class.
E.To improve cohesion, getNetworkPrinterID() should be moved to a different class.


E is correct.

Note

The getNetworkPrinterID() method implies a functionality that could be used by many different classes, not just the Main class.

A is incorrect because the code is legal.

B's change would improve encapsulation, not cohesion.

C and D's changes would have no effect on cohesion.




PreviousNext

Related