您的位置:首页 > 其它

面向对象练习

2015-08-13 09:38 281 查看
<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);

}



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: