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

  2. Each Prik has a peOl, which is an int. A peOl is part of the internal state of a Prik: no other classes can see the value of peOl or directly change it. When a Prik is first created, the value of its peOl starts out as 2.

Solution

public class Prik {
    public int peOl = 2;

    public Prik() {
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: