Is it possible to have a constructor in a class, that you can ignore certain arguments/parameters?
For example, I have this constructor
Car(color, make, model, wheels, type, doors)
Could I call this constructor and not include the type parameter?
Software Engineering Stack Exchange is a question and answer site for professionals, academics, and students working within the systems development life cycle. It only takes a minute to sign up.
Sign up to join this communityBuilder Pattern is exact solution to this problem. Especially if the combination of optional and required parameters get big, which would require tons of different constructors.
type
optional doesn't work. If bothtype
anddoors
are optional, you could use named parameters to only specifydoors
but nottype
.