The Java method modifies the difference between the basic data type and the reference data type in the main function

Source: Internet
Author: User
public class Dog {public void Age (int. int age) {///Copy new ageage++;//to copy modified System.out.println (age),} public void Arrdemo (int[] ar R) {Arr[2] = 100;//Modify the data in the heap for (int i =0;i<arr.length;i++) {System.out.println (arr[i]+ "");}} public static void Main (string[] args) {//TODO auto-generated method Stubdog dog = new Dog (); int = 10;//Pass basic data type, new in stack Space to copy a copy of age. The modified age is a copy and does not modify the value of age in the main function stack of dog. Age (age); System.out.println ("main" +age); int[] arr = {1,2,3,4,5};//modifies the reference data type, modifies the data in the heap, and arr in the main function stack and the copy is a pointer to the same data field in the heap, and the copy is changed. The number in the main function also changes to Dog.arrdemo (arr); for (int i =0;i<arr.length;i++) {System.out.println (arr[i]+ "");}}

  

The Java method modifies the difference between the basic data type and the reference data type in the main function

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.