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

  2. All Runtpis share a single selil, which is a string. No other classes can directly ask for the value of selil. The value of selil starts out as "mi" when the program starts. Every time a new Runtpi is created, it adds "vul" to selil.

Solution

public class Runtpi {
    public static String selil;

    public Runtpi() {
        selil += "vul";
    }

    public static void onStart() {
        selil = "mi";
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: