Defining a private constructor

Figure 368. Define a private Day constructor Slide presentation
public class Day {

  // Disallow object creation outside class

  private Day() {} 

  static public final Day
    MONDAY    = new Day(),
    TUESDAY   = new Day(),
  ...
    SUNDAY    = new Day();
}

Figure 369. Preventing undesired Day instance creation Slide presentation
Class Screwed:

Day PAST_SUNDAY = new Day();

Lecture phpIntro = new Lecture(
     PAST_SUNDAY, "PHP introduction");

System.out.println(phpIntro.toString());

Compile time error:

'Day()' has private access in
'de.hdm_stuttgart.mi.sd1.
class_wrapper_private.Day'

Figure 370. Adding a day name attribute Slide presentation
public class Day {
  public final String name;

  private Day(final String name) {
    this.name = name;
  }
  static public final Day
    MONDAY    = new Day("Monday"),
  ...
    SUNDAY    = new Day("Sunday");

    public String toString() { return name; }
}