本文共 877 字,大约阅读时间需要 2 分钟。
学习到宋红康String类型的一道面试题。
https://www.bilibili.com/video/BV1Kb411W75N?p=455 自己将其他的基本数据类型、对象作为参数,补充整理了一下。 代码改为:public class StringTest { int a = 0; String str = new String("good"); char[] ch = { 't', 'e', 's', 't' }; public void change(String str, char ch[], int a, Student stu) { str = "test ok"; ch[0] = 'b'; a = 1; stu.score = 1; } public static void main(String[] args) { StringTest ex = new StringTest(); Student stu1 = new Student(); ex.change(ex.str, ex.ch, ex.a, stu1); System.out.println(ex.str);//good System.out.println(ex.ch);//best System.out.println(ex.a);//0 System.out.println(stu1.score);//1 }}class Student{ int score = 0;}图上一目了然了,不多解释了。 另说明: 1、基本数据类型传的是数值,引用类型传的是地址。 2、①对象名存储在栈,形参名存储在栈,基本数据类型存储在栈。 ②对象的属性存储在堆,如果该属性的类型是String,那么它还要指向方法区的常量池。
转载地址:http://minlf.baihongyu.com/