Briefly describe what an object initializer does and give a specific example. When is the object initializer assignment made?
What will be an ideal response?
An object initializer allows you to assign values to any accessible members or properties of a class at the time of instantiation without calling a constructor with parameters. For example, assuming an Employee class has been created with a public IdNumber property and a parameterless constructor, you can write an object initializer as follows:
Employee aWorker = new Employee {IdNumber = 101};
In this statement, 101 is assigned to the aWorker object's IdNumber property. The assignment is made within a pair of curly braces; no parentheses are used with the class name. When this statement executes, the parameterless, default constructor for the class is executed first, and then the object initializer assignment is made.
You might also like to view...
Metrics that are useful for profile-based intrusion detection are: counter, gauge, resource utilization, and _________ .
Fill in the blank(s) with the appropriate word(s).
The Java ____________________ built in to the browser runs an applet on the user's computer.
Fill in the blank(s) with the appropriate word(s).
A split form displays data in two views from the same source
Indicate whether the statement is true or false
To insert mathematical equation, you use the ________ built-in gallery
Fill in the blank(s) with correct word