Java Method Pass Parameter

Source: Internet
Author: User

1. Create students class-----//Main Construction Object

http://vipnoon.blog.51cto.com/7589908/1792786

2. Create a Calc class---------//main construction method

public class Calc {public void calc1 (int num) {num = num + 1;} public void Calc2 (students stu) {Stu.setage (Stu.getage () +1);}}

3, create the Calcdemo class-----//Pass the parameter

public class Calcdemo {public static void main (string[] args) {//calc c = new Calc (); int n = 8; C.calc1 (n); students Stu = New students (); Stu.setage (+); c.calc2 (Stu); System.out.println (Stu.getage () + "\ n" +n);}}

4. Effect verification

19

8

5. Discussion

Basic data types and reference data types differ when you pass a parameter

N Num Stu Student

Memory 8 Address Replication 8+1 18 address delivery 19

Base data type, the action passes the value of the variable, and changing the value of one variable does not affect the value of the other variable.

Reference data types (classes, arrays, and interfaces), assignment is a reference to the original object (which can be understood as a memory address) passed to another reference.

String is the number of char types, and string is the reference data type.


This article is from the "Advanced Technology" blog, so be sure to keep this source http://vipnoon.blog.51cto.com/7589908/1792819

Java Method Pass Parameter

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.