Java基础之基本数据类型和引用数据类型传递图解

//基本数据类型参数传递
class Demo 
{
	public static void main(String[] args) 
	{

		int x = 3;
		show(x);
		System.out.println("x="+x);
	}
	public static void show(int x)
	{
		x = 4;
	}
}

//引用数据类型参数传递
class Demo
{
	int x = 3;
	public static void main(String[] args)
	{
		Demo d = new Demo();
		d.x = 9;
		show(d);
		System.out.println(d.x);
	}
	public static void show(Demo d)
	{
		d.x = 4;
	}
}


图解

你可能感兴趣的:(#,Java基础教程(一))