~/ learn/ java-from-zero/ cards/ Static factories & the Builder pattern
1 of 4

Type a static factory method pair

Type a static factory method pair

Answer

public static Temperature ofCelsius(double c) { return new Temperature(c); }

The private constructor is hidden; callers use the named factory. The name makes the unit explicit — no guessing whether the double argument is Celsius or Fahrenheit.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/09b46749-f44e-4ab0-bd8c-8621159f41b7/flashcard utf-8 LF