Java Topic Practice
Object State and Encapsulation
Object State and Encapsulation MCQ Practice
Question 1 of 15
Answered 0 of 15
Choose one answer.
What is printed by the following code segment?
public class Main {
public static void main(String[] args) {
Counter c = new Counter(18);
c.bump(3);
c.bump(-3);
c.bump(3);
System.out.print(c.getValue());
}
}
class Counter {
private int value;
public Counter(int start) { value = start; }
public void bump(int amount) { value += amount; }
public int getValue() { return value; }
}