Abstraction and Program Design MCQ Practice

Question 1 of 10

A marina describes a HarborBuoy in a design note: each buoy stores a latitude label and a batteryPercent. Crew can flash the lamp or report the battery. Which sentence from the note names a behavior?

  1. A. Each buoy stores a latitude label.
  2. B. Crew can flash the lamp.
  3. C. Each buoy stores a batteryPercent.
  4. D. HarborBuoy is the class being designed.

Question 2 of 10

A StageLight design lists attributes. Which row describes a class variable rather than an instance variable?

Attribute Designer note
isOn true or false for this one light
gelColor the filter color on this one light
maxWatts one shared watt limit used by every StageLight
panAngle the current angle of this one light
  1. A. isOn
  2. B. gelColor
  3. C. maxWatts
  4. D. panAngle

Question 3 of 10

Callers of a SmoothieCup method blend(int seconds) only need the cup to mix for that many seconds. They do not read the motor-speed formula inside the method. Which idea does this illustrate?

  1. A. Procedural abstraction, because the mixing steps can stay hidden if the specified timing behavior holds.
  2. B. Data abstraction only, because blend cannot store any attributes.
  3. C. A requirement that callers copy the motor-speed formula into their own classes.
  4. D. A rule that parameters are forbidden once a method exists.

Question 4 of 10

A ScoreBoard stores a point total privately. Callers use addPoints(int n) and currentScore(); they never read the stored total themselves. Which statement is the best example of data abstraction?

  1. A. The stored form of the total can stay hidden while callers use the methods.
  2. B. addPoints must print every arithmetic step it performs.
  3. C. currentScore must be an instance variable, not a method.
  4. D. The point total cannot be an attribute because methods exist.

Question 5 of 10

A MuseumTour startTour method is specified to: unlock the headset, play a welcome clip, mark the guest present, and log the start time. Which design best decomposes that behavior?

  1. A. One startTour method that calls helpers such as unlockHeadset, playWelcome, markPresent, and logStart.
  2. B. Four unrelated classes with no method that starts the tour in the specified order.
  3. C. Storing unlockHeadset as a boolean attribute instead of providing a method.
  4. D. Deleting startTour and requiring staff to perform the steps by editing source each morning.

Question 6 of 10

A WateringCan method pour() always empties 4 cups. Gardeners now need 2, 4, or 6 cups from the same kind of action. Which design generalizes the procedure?

  1. A. Change pour so it takes a cups parameter and pours that amount.
  2. B. Keep pour() unchanged and tell gardeners to run it extra times by guessing.
  3. C. Replace pour with an instance variable named cups and remove the method.
  4. D. Create no method at all and hard-code 4 cups in every caller.

Question 7 of 10

A ReceiptLine method is specified to return a single display line for an item name and a price. Its header is shown. The team wants to change how spaces are padded inside the method. Which claim is correct?

public String format(String item, int cents)
  1. A. Padding may change if format still takes an item and cents and still returns one specified display line.
  2. B. Any padding change requires renaming format, even if the header and result stay the same.
  3. C. format cannot take two parameters because that would not be procedural abstraction.
  4. D. Callers must be given the padding formula or the method is illegal.

Question 8 of 10

A camp program sketch puts unrelated pieces into one class named CampHelper. Which revision best represents the design as separate classes with attributes and behaviors?

Piece Note
camperName the name of one camper
tentColor the color of one tent
canoeAvailable whether one canoe is free
checkInCamper records that a camper arrived
  1. A. Keep everything in CampHelper because notes that mention camp must share a class.
  2. B. Use a Camper class (name, check-in), a Tent class (color), and a Canoe class (availability) instead of one mixed helper.
  3. C. Make camperName, tentColor, and canoeAvailable all class variables of CampHelper and delete behaviors.
  4. D. Represent the whole camp as a single attribute with no class.

Question 9 of 10

A bakery designs OrderSlip objects. Each slip has its own subtotal. Every slip must use the same taxRate. Programmers later change how tax is computed inside public int taxAmount() but keep that header and still return the tax in cents. Which pair of statements is correct?

  1. A. subtotal is instance data; taxRate is class data; the taxAmount internals may change if the signature and specified result stay the same.
  2. B. subtotal must be a class variable because money is involved.
  3. C. taxRate must be copied as a separate instance variable on every slip or it cannot be an attribute.
  4. D. Changing taxAmount internals is forbidden even when callers still see the same header and cents result.

Question 10 of 10

A student lists pieces of a LunchTray design: trayId stored for one tray, empty() as an action, and a shared cafeteriaName used by every tray. Which labeling is correct?

  1. A. trayId: instance attribute. empty: behavior. cafeteriaName: class attribute.
  2. B. trayId: behavior. empty: class attribute. cafeteriaName: instance attribute.
  3. C. trayId: class attribute. empty: instance attribute. cafeteriaName: behavior.
  4. D. All three pieces are behaviors and none are attributes.