2.2 Creating and Storing Objects (Instantiation)
Enduring Understanding
Some objects or concepts are so frequently represented that programmers can draw upon existing code that has already been tested, enabling them to write solutions more quickly and with a greater degree of confidence.
Learning Objectives
Identify, using its signature, the correct constructor being called.
Essential Knowledge
A signature consists of the constructor name and the parameter list.
The parameter list, in the header of a constructor, lists the types of the values that are passed and their variable names. These are often referred to as formal parameters.
A parameter is a value that is passed into a constructor. These are often referred to as actual parameters.
Constructors are said to be overloaded when there are multiple constructors with the same name but a different signature.
The actual parameters passed to a constructor must be compatible with the types identified in the formal parameter list.
Parameters are passed using call by value. Call by value initializes the formal parameters with copies of the actual parameters.
Learning Objective
For creating objects:
a. Create objects by calling constructors without parameters.
b. Create objects by calling constructors with parameters.
Essential Knowledge
Every object is created using the keyword new followed by a call to one of the class’s constructors.
A class contains constructors that are invoked to create objects. They have the same name as the class.
Existing classes and class libraries can be utilized as appropriate to create objects.
Parameters allow values to be passed to the constructor to establish the initial state of the object.
Enduring Understanding
To find specific solutions to generalizable problems, programmers include variables in their code so that the same algorithm runs using different input values.
Learning Objective
Define variables of the correct types to represent reference data.
Essential Knowledge
The keyword null is a special value used to indicate that a reference is not associated with any object.
The memory associated with a variable of a reference type holds an object reference value or, if there is no object, null. This value is the memory address of the referenced object.
Last updated
Was this helpful?