Home > Java > javaTutorial > What is a reference variable in java?

What is a reference variable in java?

青灯夜游
Release: 2020-08-18 11:20:12
Original
9134 people have browsed it

The essence of a variable is a small memory unit, which stores the value of the variable; when a variable points to an object, the variable is called a reference variable. Java's reference variable is actually a pointer, which points to an object instance in the heap memory, which is equivalent to an alias for an array or object.

What is a reference variable in java?

Recommended: "Java Video Tutorial"

First of all, you have to understand what a variable is. The essence of a variable is a small memory unit, which stores the value of the variable

For example, int a = 1;

a is the name of the variable, and 1 is the value of the variable.

When a variable points to an object, the variable is called a reference variable

For exampleA a =new A();

a is a reference variable. It points to an A object. It can also be said that it refers to an A object. We operate the A object by manipulating this a. At this time, the value of variable a is the address of the object it refers to.

If you have learned C, you can think of it as a pointer. Although it is actually different from a pointer, conceptually it is not impossible to use it as a pointer in JAVA.

Java's reference variable is actually a pointer. It points to an object instance in the heap memory. It is equivalent to an alias for an array or object. You can use the stack in the program later. A reference variable to access an array or object in the heap.

The picture below is reproduced in more detail from the original article. . . I don’t know where it is. If the original author sees it, please let me know.

What is a reference variable in java?

For more programming-related knowledge, please visit: Introduction to Programming! !

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