Abstraction and Program Design MCQ Practice

Question 1 of 10

A volunteer desk uses a LostItemTag. In everyday language: each tag stores a color and a bin number. A clerk can print the tag or mark it claimed. Which option correctly identifies the class, one attribute, and one behavior?

  1. A. Class: print the tag. Attribute: LostItemTag. Behavior: color.
  2. B. Class: LostItemTag. Attribute: bin number. Behavior: mark the tag claimed.
  3. C. Class: color. Attribute: mark claimed. Behavior: bin number.
  4. D. Class: bin number. Attribute: LostItemTag. Behavior: print the tag.

Question 2 of 10

A design sketch for a RecitalSeat is shown. Which proposed piece names a behavior rather than an attribute?

Proposed piece Designer note
aisleLetter a letter such as A or C stored for this seat
rowNumber an integer stored for this seat
reserved true or false stored for this seat
cancelHold an action this seat can carry out
  1. A. aisleLetter
  2. B. rowNumber
  3. C. reserved
  4. D. cancelHold

Question 3 of 10

A HallLocker object stores a combination. Callers use tryCombo(int n) and never read the stored combination directly. Which statement best distinguishes data abstraction from procedural abstraction in this design?

  1. A. Data abstraction: callers need not know how the combination is stored. Procedural abstraction: callers need not know the steps inside tryCombo.
  2. B. Data abstraction: the method name tryCombo. Procedural abstraction: the stored combination.
  3. C. Data abstraction: printing output. Procedural abstraction: compiling the class.
  4. D. Data abstraction: using a second class named Combination. Procedural abstraction: renaming HallLocker.

Question 4 of 10

A movie house designs Seat objects. Every seat object has its own reserved flag. All seats share one ticketPrice used by the whole house. Which statement matches that design?

  1. A. reserved and ticketPrice are both class variables.
  2. B. reserved is an instance variable; ticketPrice is a class variable.
  3. C. reserved is a class variable; ticketPrice is an instance variable.
  4. D. Neither reserved nor ticketPrice is an attribute.

Question 5 of 10

A snack kiosk specifies payForSnack as: confirm the item, add tax, take payment, print a receipt, and open the drawer. Which design best uses method decomposition?

  1. A. Keep every step inside one giant method with no helper methods.
  2. B. Provide helper methods such as addTax, takePayment, and printReceipt that payForSnack calls in order.
  3. C. Store addTax, takePayment, and printReceipt as instance variables of type int.
  4. D. Replace the kiosk class with five unrelated classes that never call one another.

Question 6 of 10

A courtyard fountain class has spray() that always runs for 8 seconds. Designers want one procedure that can spray for 8, 12, or 20 seconds. Which change generalizes the procedure with a parameter?

  1. A. Add a seconds parameter to spray and use that value as the duration.
  2. B. Copy spray into spray8, spray12, and spray20 with the times hard-coded.
  3. C. Convert spray into an instance variable named seconds.
  4. D. Remove spray and require callers to edit the class source before each use.

Question 7 of 10

A BadgePrinter method is specified to print a guest name on one line. Its current header is shown. Which internal change is allowed if the header and the specified one-line printing behavior stay the same for callers?

public void printName(String name)
  1. A. Drop the name parameter so the method prints a fixed sample string.
  2. B. Keep printName(String name) but switch to a different printer library call that still prints the name on one line.
  3. C. Require callers to construct a second helper class before every printName call.
  4. D. Change the method so callers must pass two names instead of one.

Question 8 of 10

A first-year team sketches one class named SchoolHelper. The table lists proposed pieces. Which criticism is most justified?

Piece Kind Note
studentLastName attribute belongs to one student
lockerCombo attribute belongs to one locker
gradeOnQuiz attribute belongs to one quiz attempt
printHallPass behavior prints a hall pass for a student
  1. A. The sketch is fine because any school idea may share a single class.
  2. B. The sketch mixes unrelated objects' data into one class instead of separate Student, Locker, and QuizAttempt designs.
  3. C. printHallPass cannot be a behavior because behaviors are never methods.
  4. D. Attributes are not allowed when a class also has behaviors.

Question 9 of 10

A kiosk company wants a running total of how many Kiosk objects have been constructed, plus each kiosk's own serialLabel. Which assignment of attributes is appropriate?

  1. A. Both the running total and serialLabel should be class variables only.
  2. B. The running total should be a class variable; serialLabel should be an instance variable.
  3. C. The running total should be an instance variable; serialLabel should be a class variable.
  4. D. Neither value can be represented as an attribute.

Question 10 of 10

A TrailMap class stores path data privately and offers public int walkTime(String start, String end), specified to return minutes. Callers never inspect the stored path data. Which statement is accurate?

  1. A. Hiding how path data is stored is data abstraction; hiding the walk-time steps is procedural abstraction; start and end generalize the procedure.
  2. B. Parameters are illegal whenever stored data is private.
  3. C. If programmers later store path data differently, they must rename walkTime even if it still returns minutes.
  4. D. walkTime must not take parameters because abstraction forbids inputs.