Introduction to the Java language Tutorial (ix): value delivery in the Java language

Source: Internet
Author: User

In the eighth article posting, the author introduces the basic knowledge that the method body must understand, and the beginner can practice it by writing a simple example. In the course of practice, we can not put all the code in the main method, Java class must have more or less method members, call these methods will be necessary steps. When a method member is invoked, if the method has arguments, it must pass the actual argument to the formal argument of the method. So it is necessary to understand the value transfer in the Java language.

The data types in Java are divided into two categories, basic data types and reference types. Therefore, the value transfer characteristics of the two data types are also introduced in this paper.

1. Value delivery of the base data type: The base data type passes a value.

The following procedure:

Package com.csst.test;
public class Test5 {
    /**
     * @param args
     *
    /public void Printx (int x) {
       + +;
       System.out.println ("printx:x=" +x);
    }
    public static void Main (string[] args) {
       //TODO auto-generated method stub
       Test5 test5=new Test5 ();
       int x=10;
       Test5.printx (x);
       System.out.println ("main:x=" +x);
    }

The results of the operation are as follows:

printx:x=11

main:x=10

Thus, when the base data type X is passed to the Printx method, only the value 10 is passed to the parameter x, so the parameter X plus 1 outputs 11, while the X in the main method is still 10.

Related Article

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.