Techniques of Initializing a Class

There are various techniques used to initialize a class: initializing individual members or initializing the class as a whole.

To initialize a member of a class, access it and assign it an appropriate value.

This time, the program would render a reasonable result.

The Phoenix Project
Transform your IT and business with The Phoenix Project – the gripping story that redefines how we think about DevOps and innovation!
View on Amazon

You can also initialize an object as a variable. This time, type the name of the variable followed by the assignment operator, followed by the desired values of the variables listed between an opening and a closing curly brackets; each value is separated with a comma. The first rule you must keep in mind is that the list of variables must follow the order of the declared members of the class. The second rule you must observe is that none of the members of the class must be another class. In the following example, one of the members of the class is another class, namely a string. Because of the way a variable of the class is declared, the program would not compile: