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 Peldin.

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

Solution

public class Peldin {
    public List<String> siInste = new ArrayList<>();

    public Peldin() {
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: