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

  2. All Silis share a single olDa, which is an int. No other classes can directly ask for the value of olDa. The value of olDa starts out as 19 when the program starts. Every time a new Sili is created, it adds 7 to olDa.

Solution

public class Sili {
    public static int olDa;

    public Sili() {
        olDa += 7;
    }

    public static void onStart() {
        olDa = 19;
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: