Object data type as an argument

Source: Internet
Author: User

Just in touch with Java, read the Ushimaki teacher's video, Java's parameter passing Way is a: "Pass value".

public class Human {

public static void swap(int iNum, int jnum)

{

int temp = INum;

INum = Jnum;

Jnum = temp;

}

public static void init(Student St)

{

Student temp = st;

St.name = "I was created in Init";

}

public static void Main (string[] args) {

TODO auto-generated Method Stub

int i = 10;

int j = 7;

Swap (I, j);

System.out.println ("i=" +i + ", j=" +j);//actually not exchanged, still i=10,j=7

Student stu1 = new Student ();

Human. Init (STU1);

System.out.println ("stu1 name =" +stu1.name);//display: I was created in Init

}


}


In Java, when an object is passed as an argument, the reference to the address should be passed correctly, so it will be modified in the Init method and printed in the Main method.


Base data type as an argument: copy a copy

Object data types as arguments: delivery of addresses (similar to C + +)


I'm just a beginner, hoping to get more knowledge in my mistakes.

Object data type as an argument

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.