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

  2. All Bestas share a single avi, which is a string. No other classes can directly ask for the value of avi. The value of avi starts out as "ste" when the program starts. Every time a new Besta is created, it adds "ce" to avi.

Solution

public class Besta {
    public static String avi;

    public Besta() {
        avi += "ce";
    }

    public static void onStart() {
        avi = "ste";
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: