viewing paste Unknown #27604 | 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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
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 make the static DEFAULT_DSCR mutable, removing its final status, as in:
 
   static public String DEFAULT_DSCR = "(generic phone)";
A mutator is added for this member. Any String whose length is at least 2 characters will be acceptable as a new DEFAULT_DSCR.
 
Check the true statements (there may be more than one correct answer):
 
 
 
        A.      The mutator for this member will be an instance method.
        B.      If the mutator takes a String parameter, newDefault, a reasonable definition would be:
      if ( newDefault.length() < 2 )
         return false;
      DEFAULT_DSCR = newDefault;
      return true;
        C.      The mutator for this member will be a static method.
        D.      If the mutator takes a String parameter, newDefault, a reasonable definition would be:
   if ( newDefault.length() < 2 )
   {
      this.newDefault = DEFAULT_DSCR;
      return false;
   }
   this.newDefault = newDefault;
   return true;
        E.      If the mutator takes a String parameter, newDefault, a reasonable definition would be:
   if ( newDefault.length() > 0 )
      return false;
   DEFAULT_DSCR = newDefault;
   return true;
Viewed 550 times, submitted by unknown.