面向對象練習

<pre name="code" class="java">OOP練習
public static void main(String[] args) throws CloneNotSupportedException {
		StringBuffer sb = new StringBuffer("abc");
		StringBuffer sb2 = sb;
		sb.append("ABC");
		System.out.println("sb = " + sb);
		System.out.println("sb2 = " + sb2);  //sb2值改變,和sb引用桶一個變量
		
		String str = "abc";
		String str2 = str;
		str += "123";
		System.out.println("str = "+str);     
		System.out.println("str2 = "+str2); //不改變
		
		int i = 1;
		int ii = i;
		i++;
		System.out.println("i = "+ i);
		System.out.println("ii = "+ ii);   //不改變
		
		CloneDemo cd = new CloneDemo();
		cd.name = "CloneDemoFather";
		CloneDemo cd2 = cd.clone();
		System.out.println(cd2.name);
		
	}



發佈了30 篇原創文章 · 獲贊 5 · 訪問量 20萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章