Java Topic Practice
Object State and Encapsulation
Practice mode with 15 Java-focused questions, immediate answer checks, and explanations.
For practice use only.
Object State and Encapsulation MCQ Practice
Object State and Encapsulation Java practice with 15 questions, code tracing, and a worked explanation for every answer.
Question 1 of 15
Answered 0 of 15
Choose one answer.
Code Tracing 01 - Object State and Encapsulation: track the final printed value.
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; }
}