Home > Java > JavaBase > body text

What is an object reference in java

angryTom
Release: 2019-11-16 16:18:03
Original
6291 people have browsed it

What is an object reference in java

What is an object reference in java

1. The concept of reference

If a variable The type is a class type, not a basic type, then the variable is also called a reference. In fact, GC mainly depends on whether the object has a reference pointing to the object. According to the strong and weak relationship of this reference, starting from JDK1.2 version, object references are divided into four levels, so that the program can more flexibly control the life cycle of the object. These four levels, from high to low, are: strong reference, soft reference, weak reference and virtual reference.

2. Object reference

Reference and pointer

new Hero(); represents the creation of a Hero object, but it only creates an object and has no way to access it. In order to access this object, a reference will be used to represent the object Hero h = new Hero();

hThis variable is of type Hero, also called a reference, = It means that the reference h represents the object created on the right "representative". In object-oriented, it is also called "pointing".

So, the reference to an object in Java is a class type variable pointing to the created object.

php Chinese website, a large number of free Java introductory tutorials, welcome to learn online!

The above is the detailed content of What is an object reference 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!