Anatomy of a Class MCQ Practice

Question 1 of 10

A radio program needs a type for one studio clock. Which statement follows AP CSA class anatomy?

  1. A. The StudioClock class may be private if only one file uses it.
  2. B. The StudioClock class is designated public.
  3. C. The StudioClock class omits an access keyword so it stays hidden.
  4. D. The StudioClock class is protected so related classes can share it.

Question 2 of 10

A Mixer constructor must be callable as new Mixer(3). Which header is required?

  1. A. public Mixer(int knobs)
  2. B. private Mixer(int knobs)
  3. C. void Mixer(int knobs)
  4. D. protected Mixer(int knobs)

Question 3 of 10

Two microphone stands are separate objects. What text does this Java code display?

public class MicStand {
    private int height;
    public MicStand(int start) {
        height = start;
    }
    public void raise(int extra) {
        height += extra;
    }
    public int getHeight() {
        return height;
    }
}

MicStand a = new MicStand(110);
MicStand b = new MicStand(110);
a.raise(15);
System.out.print(a.getHeight() + " " + b.getHeight());
  1. A. 125 125
  2. B. 110 125
  3. C. 125 110
  4. D. 15 110

Question 4 of 10

A client has Reel r = new Reel(50);. Which statement compiles?

public class Reel {
    private int meters;
    public Reel(int n) {
        meters = n;
    }
    public int getMeters() {
        return meters;
    }
    private void rewind() {
        meters = 0;
    }
    public void clear() {
        rewind();
    }
}
  1. A. r.meters = 10;
  2. B. r.rewind();
  3. C. int m = r.meters;
  4. D. r.clear();

Question 5 of 10

A fader uses an internal helper. What text does this Java code display?

public class Fader {
    private int level;
    public Fader() {
        level = 0;
    }
    private void bump() {
        level++;
    }
    public void fadeUp() {
        bump();
        bump();
    }
    public int getLevel() {
        return level;
    }
}

Fader f = new Fader();
f.fadeUp();
System.out.print(f.getLevel());
  1. A. 0
  2. B. 1
  3. C. 2
  4. D. The code does not compile because bump is private.

Question 6 of 10

A cue card is updated through public methods. What text does this Java code display?

public class CueCard {
    private String line;
    public CueCard(String start) {
        line = start;
    }
    public void append(String extra) {
        line = line + extra;
    }
    public String getLine() {
        return line;
    }
}

CueCard c = new CueCard("INTRO");
c.append("-GO");
System.out.print(c.getLine());
  1. A. INTRO
  2. B. INTRO-GO
  3. C. -GO
  4. D. INTROGO

Question 7 of 10

Using JackBox, which row correctly describes client access?

public class JackBox {
    private int ports;
    public JackBox(int n) {
        ports = n;
    }
    public int getPorts() {
        return ports;
    }
}
Row Client statement Compiles?
1 JackBox j = new JackBox(8); yes
2 int n = j.getPorts(); yes
3 j.ports = 4; ?
4 int n = j.ports; ?
  1. A. Rows 3 and 4 both compile because the constructor is public.
  2. B. Row 3 compiles and row 4 does not.
  3. C. Row 4 compiles and row 3 does not.
  4. D. Rows 3 and 4 do not compile because ports is private.

Question 8 of 10

Two booth lamps start unlit. What text does this Java code display?

public class BoothLamp {
    private boolean lit;
    public BoothLamp() {
        lit = false;
    }
    public void on() {
        lit = true;
    }
    public boolean isLit() {
        return lit;
    }
}

BoothLamp left = new BoothLamp();
BoothLamp right = new BoothLamp();
right.on();
System.out.print(left.isLit() + " " + right.isLit());
  1. A. true true
  2. B. true false
  3. C. false true
  4. D. false false

Question 9 of 10

A specification says client code must assign the public instance variable live of an OnAirLight. Which choice matches the specification and usual class rules?

  1. A. private boolean live; and no public methods, because fields are always hidden
  2. B. public boolean live; because this specification says otherwise
  3. C. The OnAirLight class must be private so live can be public
  4. D. live must be a constructor parameter only, never stored

Question 10 of 10

A dial uses a private helper. What text does this Java code display?

public class Dial {
    private int ticks;
    public Dial() {
        ticks = 4;
    }
    private void nudge() {
        ticks++;
    }
    public void tune() {
        nudge();
    }
    public int getTicks() {
        return ticks;
    }
}

Dial d = new Dial();
d.tune();
System.out.print(d.getTicks());
  1. A. 4
  2. B. 5
  3. C. 6
  4. D. The code does not compile because nudge is private.