Home > Java > JavaBase > what is java instantiation

what is java instantiation

angryTom
Release: 2019-11-12 09:55:09
Original
6415 people have browsed it

what is java instantiation

What is java instantiation

Persion p1 = new Persion();
Copy after login

Java instantiation is to create an object using the new keyword The process, for example, "new Persion()" means instantiating a Persion object, where the parentheses at the end of Persion mean that the constructor of the Persion class is immediately called to perform the initialization operation. , in fact, it contains four actions. (Recommended tutorial: java tutorial)

1) The "new Persion" on the right is based on the Persion class As a template, create a Persion class object (also referred to as Persion object) in the heap space.

2) The () at the end means that after the object is created, the constructor of the Persion class is called immediately to initialize the newly generated object. There is definitely a constructor. If you don't write it, Java will add a default constructor for you.

3) "Persion p1" on the left creates a Persion class reference variable. The so-called Persion class reference is an object reference that can be used to point to the Persion object in the future.

4) The "=" operator makes the object reference point to the Persion object just created.

Example:

class A {
    int i;
}
Copy after login

Here A is a class

and the object is a specific one of the class, such as

A a1 = new A();
A a2 = new A();
Copy after login

a1 a2 are all objects

And the process of creating an object is called instantiation

So sometimes we also call the object an instance of a class.

The above is the detailed content of what is java instantiation. 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 admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template