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

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

Solution

public class Roplo {
    public int ceRa = 14;

    public Roplo() {
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: