Similar to methods, we can also define initializers with optional parameters. It is necessary to assign initial values to class properties when defining the class. So, when defining an initializer with optional parameters, it’s essential to assign default values to the properties.
You can also have a default initializer that has all properties as optional. In this case, all the new objects will be created using the properties initialized in the initializer definition.
Below is an example where one Employee class object is created without the initializer parameters and one is created with the initializer parameters.