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

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

Solution

public class Sphelpim {
    public int ang = 17;

    public Sphelpim() {
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: