Application Program Interface (API) and Libraries MCQ Practice

Question 1 of 10

A ranger program uses classes that other programmers already wrote for maps, weather, and permits. Those classes live together as reusable units. Which description fits best?

  1. A. The ranger is limited to primitive int values only.
  2. B. The ranger is using a library of classes through its API.
  3. C. The ranger must rewrite every class before compiling.
  4. D. The ranger is writing comments that the compiler executes.

Question 2 of 10

Why is API documentation essential even when the library class files are installed?

  1. A. It describes documented attributes and behaviors so the classes can be used correctly.
  2. B. It prints every method body onto the screen automatically.
  3. C. It converts reference types into int.
  4. D. It makes undocumented methods safe to invent.

Question 3 of 10

Which pairing is correct?

  1. A. Attributes are data stored in variables; behaviors are defined by methods.
  2. B. Attributes are packages; behaviors are primitive types.
  3. C. Attributes are comments; behaviors are compilers.
  4. D. Attributes are always void methods; behaviors are always ints.

Question 4 of 10

This fictional TrailKiosk API documents only the members below. Which member is a behavior rather than stored data?

Member Kind Contract
mapsLeft attribute int number of printed trail maps
dispense method decreases mapsLeft by 1 if mapsLeft is positive
restock method adds the given int to mapsLeft
countMaps method returns mapsLeft
  1. A. mapsLeft
  2. B. dispense
  3. C. The package name
  4. D. The class name TrailKiosk

Question 5 of 10

mapsLeft starts at 1. Using only the TrailKiosk contract, dispense is used twice. What does countMaps return afterward?

Member Kind Contract
mapsLeft attribute int number of printed trail maps
dispense method decreases mapsLeft by 1 if mapsLeft is positive
restock method adds the given int to mapsLeft
countMaps method returns mapsLeft
  1. A. -1
  2. B. 1
  3. C. 2
  4. D. 0

Question 6 of 10

A volunteer wants TrailKiosk to email a map as a PDF. The only documentation is the table below. What is the sound approach?

Member Kind Contract
mapsLeft attribute int number of printed trail maps
dispense method decreases mapsLeft by 1 if mapsLeft is positive
restock method adds the given int to mapsLeft
countMaps method returns mapsLeft
  1. A. Call emailPdf, assuming libraries include every feature a name could suggest.
  2. B. Use restock and dispense as if they sent email.
  3. C. Stay with documented members, or obtain a different API that documents the needed behavior.
  4. D. Write a comment claiming emailPdf exists so clients can call it.

Question 7 of 10

This HarborCrane API documents only the members below. After lift is used with 40, then clear is used, what does readLoad return?

Member Kind Contract
loadKg attribute int mass currently on the hook
lift method sets loadKg to the given int
clear method sets loadKg to 0
readLoad method returns loadKg
  1. A. 40
  2. B. 0
  3. C. The previous unknown load
  4. D. A boolean

Question 8 of 10

Which statement correctly relates libraries, classes, and packages?

  1. A. A package is one primitive value, and a library is one comment.
  2. B. Libraries collect reusable classes, and packages group classes.
  3. C. A class is a collection of all installed libraries.
  4. D. A library is always a single object in memory.

Question 9 of 10

Which item is most naturally a behavior of a darkroom timer?

  1. A. Stored remaining seconds
  2. B. The timer's brand string
  3. C. Decreasing the remaining seconds by one tick
  4. D. The factory serial number

Question 10 of 10

This DarkroomTimer API documents only the members below. seconds starts at 3. tick is used twice, then remaining is used. What value is returned?

Member Kind Contract
seconds attribute int remaining darkroom time
wind method sets seconds to the given int
tick method decreases seconds by 1 if seconds is positive
remaining method returns seconds
  1. A. 3
  2. B. 1
  3. C. 0
  4. D. 2