The new operator
The new operator is used in the context of an assignment.
General form:
var-class = new class-name(list-arg);
var-class is a variable of the type of the class being created.
class-name is the name of the class being instantiated.
The class name followed by a list of arguments specifies the class constructor.
If the class does not define a constructor, new will use Java's default constructor.
new creates an object of any class type and returns a reference to the created object.
The reference to the newly created object is assigned to var-class.
new may fail if there is not enough memory to allocate the object.
If this occurs, there will be a runtime exception. In the examples in the book, lack of memory is not a concern, but it is relevant in real-world programs.
The above is the detailed content of The new operator. For more information, please follow other related articles on the PHP Chinese website!