Home > Java > Java Tutorial > body text

What does new mean in java?

little bottle
Release: 2019-05-25 13:28:35
Original
21113 people have browsed it

"new" can be said to be the most commonly used keyword by Java developers. We use new to create objects, use new and instantiate anything we need through the class loader.

What does new mean in java?

Using the new keyword in Java makes it easy to create objects.

Need to access a file? Just create a new File instance: new File("jdbc.properties")

Instantiate a class object

The new operator instantiates a class object by allocating memory to this object and returns a reference to that memory. The new operator also calls the object's constructor.

Note: "Instantiate an object of a class" means "create an object". When you create an object, you are creating an "instance" of a class, thus "instantiating" an object of the class.

The new operator requires a single, suffix parameter, which requires calling the constructor. The name of the constructor provides the name of the class that needs to be instantiated.

The new operator returns a reference to the object it creates. This reference is usually assigned to a variable of the appropriate type, such as: Point originone = new Point (23, 94);

The reference returned by the new operator does not need to be assigned to a variable. It can also be used directly in an expression. For example: int height = new Rectangle().height;

Summary:

1. The Java keyword new is an operator. It has the same or similar precedence as , -, *, / and other operators.

2. Creating a Java object requires three steps: declaring reference variables, instantiating, and initializing object instances.

3. Instantiation: It is to "create a Java object" ----- allocate memory and return a reference to the memory.

4. Initialization: It means calling the constructor method and assigning an initial value to the instance data of the class.

The above is the detailed content of What does new mean in java?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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 [email protected]
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!