Home > Java > javaTutorial > The new operator

The new operator

WBOY
Release: 2024-07-31 12:31:32
Original
857 people have browsed it

O operador new

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!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template