Class declarations and object modeling: Correct Solution


Translate the specification below into an idiomatic Java class definition.

(In this context, "idiomatic" means following the common style and conventions of the language.)

  1. One kind of thing that exists in our model is a Carbla.

  2. Each Carbla has a haNass, which is a list of strings. A haNass is part of the internal state of a Carbla: no other classes can see the value of haNass or directly change it. When a Carbla is first created, the value of its haNass starts out as an empty mutable list.

Solution

public class Carbla {
    public List<String> haNass = new ArrayList<>();

    public Carbla() {
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: