Skip to main content

Unit 3 · Class Creation

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 Acc
{
    private int total;
    public void add(int v)
    {
        total += v;
    }
    public int getTotal()
    {
        return total;
    }
}

Acc a = new Acc();
a.add(3);
a.add(4);
System.out.print(a.getTotal());
Choose one answer.