Question 1 of 10
A nursery program models one greenhouse tray. Which class header matches the AP CSA requirement for a class?
- A. public class Tray
- B. private class Tray
- C. protected class Tray
- D. class Tray with no access keyword
A nursery program models one greenhouse tray. Which class header matches the AP CSA requirement for a class?
A Locker class needs a constructor that receives an int combination. Which constructor header is required?
The question specification does not mention a special access rule for humidity. How should that Greenhouse attribute be designated?
Each Planter object keeps its own soilMoisture. What text does this Java code display?
public class Planter {
private int soilMoisture;
public Planter(int start) {
soilMoisture = start;
}
public void water(int extra) {
soilMoisture += extra;
}
public int getSoilMoisture() {
return soilMoisture;
}
}
Planter left = new Planter(4);
Planter right = new Planter(4);
left.water(3);
System.out.print(left.getSoilMoisture() + " " + right.getSoilMoisture());
A client constructs a Mister. Which statement about calling its methods is correct?
public class Mister {
private int bursts;
public Mister() {
bursts = 0;
}
private void addBurst() {
bursts++;
}
public void mistOnce() {
addBurst();
}
public int getBursts() {
return bursts;
}
}
A greenhouse tags one plant. What text does this Java code display?
public class Tag {
private String code;
public Tag(String start) {
code = start;
}
public void stamp(String extra) {
code = code + extra;
}
public String getCode() {
return code;
}
}
Tag t = new Tag("G");
t.stamp("12");
System.out.print(t.getCode());
A client already has Bench b = new Bench(6);. Which additional statement compiles?
public class Bench {
private int seats;
public Bench(int n) {
seats = n;
}
public int getSeats() {
return seats;
}
private void hide() {
seats = 0;
}
public void fold() {
hide();
}
}
Two shade cloths are separate objects. What text does this Java code display?
public class Shade {
private boolean down;
public Shade() {
down = false;
}
public void lower() {
down = true;
}
public boolean isDown() {
return down;
}
}
Shade north = new Shade();
Shade south = new Shade();
north.lower();
System.out.print(north.isDown() + " " + south.isDown());
A question specification states that client code should read and write the instance variable width of a Frame. Which declaration matches that specification?
A valve uses a private helper. What text does this Java code display?
public class Valve {
private int turns;
public Valve() {
turns = 2;
}
private void spin() {
turns++;
}
public void open() {
spin();
spin();
}
public int getTurns() {
return turns;
}
}
Valve v = new Valve();
v.open();
System.out.print(v.getTurns());