A wonderful flower in Java

Source: Internet
Author: User

In Java, only references, not pointers;

In fact, what does the reference in Java have to do with pointers in c++/c?

There are several basic types of data in Java: Boolean,int,float,double,byte ....

1. For a non basic type, a reference to a variable in Java (that is, the variable you define) is actually equivalent to the pointer

2. For basic types, this is not the case. The basic type in Java is the value itself, not the reference

Talk is cheap,show your My Code

public class intarray{public
    static void Main (string[] args) {
       int x=0;
       Intarray intarray=new Intarray ();
       Intarray.method (x);
        SYSTEM.OUT.PRINTLN (x);

    }
    public void method (int x) {
        x=2
    }
        }

The result of the output is still 0; the value of x is not modified, that is, the start of X being passed in the value itself, not the reference to X (that is, the conceptual pointer).


Note, however, that if you pass an array name of the base type, it is also equivalent to passing an array pointer in C + +.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.