Java Topic Practice
Classes and Constructors
Classes and Constructors 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) {
Tracker t = new Tracker(18);
t.add(3);
t.add(5);
System.out.print(t.getValue());
}
}
class Tracker {
private int value;
public Tracker(int start) { value = start; }
public void add(int amount) { value += amount; }
public int getValue() { return value; }
}