zoukankan      html  css  js  c++  java
  • 【Java面试题】方法的参数传递机制

    方法的参数传递机制    

      1、形参是基本数据类型    

        * 传递数据值

      2、实参是引用数据类型

        * 传递地址值

        * 特殊的类型:String、包装类等对象不可变形

     1 package com.test.code;
     2 
     3 import java.util.Arrays;
     4 
     5 /**
     6  * 方法的参数传递机制
     7  * 1、形参是基本数据类型
     8  *   传递数据值
     9  * 2、实参是引用数据类型
    10  *   传递地址值
    11  *   特殊的类型:String、包装类等对象不可变形
    12  *
    13  */
    14 public class Example {
    15 
    16     public static void main(String[] args) {
    17         int i = 1;
    18         String str = "hello";
    19         Integer num = 200;
    20         int[] arr = {1, 2, 3, 4, 5};
    21         MyData my = new MyData();
    22 
    23         change(i, str, num, arr, my);
    24 
    25         System.out.println("i = " + i);
    26         System.out.println("str = " + str);
    27         System.out.println("num = " + num);
    28         System.out.println("arr = " + Arrays.toString(arr));
    29         System.out.println("my.a = " + my.a);
    30     }
    31 
    32     private static void change(int j, String s, Integer n, int[] a, MyData m) {
    33         j += 1;
    34         s += "world";
    35         n += 1;
    36         a[0] += 1;
    37         m.a += 1;
    38     }
    39 
    40     static class MyData {
    41         int a = 10;
    42     }
    43 
    44 }
  • 相关阅读:
    LeetCode 485. Max Consecutive Ones
    LeetCode 367. Valid Perfect Square
    LeetCode 375. Guess Number Higher or Lower II
    LeetCode 374. Guess Number Higher or Lower
    LeetCode Word Pattern II
    LeetCode Arranging Coins
    LeetCode 422. Valid Word Square
    Session 共享
    java NIO
    非阻塞IO
  • 原文地址:https://www.cnblogs.com/h--d/p/13047199.html
Copyright © 2011-2022 走看看