Instantiation Statement
Purpose:
- To create an instance of a class and call the constructor for that instance.
Mechanics:
<variable name> = new <class name>();
Example:
Shape circle;circle = new Shape();
Usage:
- <variable name> is a variable or parameter of the same type as <class name>.
- When executed, Java will create an new instance of <class name> and call the constructor for the <class name> on the new instance. A reference to the new object is stored in <variable name>.
- Note that
newis a function, so it can be the initial value assigned to a variable at declaration. In other words, you can say:Shape circle = new Shape();
email suggestions to: cs015tas@cs.brown.edu
