viewing paste Unknown #27598 | Text

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
Here is an outline for a working class OldCellPhone that has no errors (you may see this exact class several times in this exam):
 
class OldCellPhone
{
   static public final int MIN_CAP = 10;
   static public final int MAX_CAP = 1000;
   static public final String DEFAULT_DSCR = "(generic phone)";
 
   private String description;
   private int   memCapacity;
   private boolean   camera;
   private boolean   gps;    
 
   public void setCamera( boolean hasCam ) { camera = hasCam; }
   public void setGps( boolean hasGps ) { gps = hasGps; }
 
   public OldCellPhone()
   {
      this(DEFAULT_DSCR, MIN_CAP, false, false);
   }
 
   public OldCellPhone(String dscr, int mem, boolean cam, boolean gp)
   {
      // not shown
   }
 
   public String toString()
   {
      // not shown
   }
 
   public boolean setMemCapacity(int mem)
   {
      // not shown
   }
};
A programmer decides to add a method addMemory() whose job it will be to increase the private int memCapacity by an amount specified by the client as long as the new, increased memory capacity after increasing it is still <= MAX_CAP.  Otherwise, it will not touch memCapacity.
 
Check the true statements (there may be more than one correct answer):
 
        A.      This should be a static method.
        B.      This should be an instance method.
        C.      If correctly defined, a client could add 30 units of memory to the OldCellPhone object, myCell, by using the syntax:
   OldCellPhone.addMemory( myCell(30) );
        D.      If correctly defined, a client could add 30 units of memory to the OldCellPhone object, myCell, by using the syntax:
   OldCellPhone.addMemory( 30 );
        E.      If correctly defined, a client could add 30 units of memory to the OldCellPhone object, myCell, by using the syntax:
   myCell.addMemory( 30 );
Viewed 602 times, submitted by unknown.