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

  2. Each Cirkcing has its own velir, which is an int. The value of velir starts out as 18. Anyone can ask a Cirkcing for the value of its velir. Anyone can set velir to a new value.

Solution

public class Cirkcing {
    private final int velir;

    public Cirkcing() {
    }

    public int getVelir() {
        return velir;
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: