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

  2. Each Hungs has its own palde, which is an int. The value of palde is specified when a Hungs is created. Anyone can ask a Hungs for the value of its palde. Anyone can set palde to a new value.

Solution

public class Hungs {
    private final int palde;

    public Hungs(int palde) {
        this.palde = palde;
    }

    public int getPalde() {
        return palde;
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: