Question 1 of 10
Lumen Workshop finds the lantern with the most oil using getters. What text does this Java code display?
public class Lantern {
private int oil;
public Lantern(int oil) {
this.oil = oil;
}
public int getOil() {
return oil;
}
}
ArrayList<Lantern> row = new ArrayList<Lantern>();
row.add(new Lantern(6));
row.add(new Lantern(11));
row.add(new Lantern(9));
int max = row.get(0).getOil();
for (int i = 1; i < row.size(); i++) {
if (row.get(i).getOil() > max) {
max = row.get(i).getOil();
}
}
System.out.print(max);
- A. 6
- B. 11
- C. 9
- D. 26