java的一些基本容易混淆的概念
1.String str=new String("helloWorld")和String str="helloWorld"的區別String str="helloWorld"是把"helloWorld"(地址)引用給str;
String str=new String("helloWorld")是新建"helloWorld"的對象,再將這個對象引用給str.
在我看來是"helloWorld"的地址由于String str=new String("helloWorld")而重新分配了.這樣對性能很不好.
2.Math.round(11.5)和 Math.round(-11.5)的結果是多少
System.out.println("Round="+Math.round(11.5));//12
System.out.println("Round="+Math.round(-11.5));//-11
--------------------------->
-11.5 0 11.5
就是我學習的約等于,四舍五入
3.short的運算符
short s1 = 1; s1 = s1 + 1
是錯誤的,可以改成:short s1 = 1; s1 =(short)( s1 + 1);
也可以是short s1 = 1; s1 +=1;
4.Overload和Override的區別
Overload是方法重寫,就是父和子類的多態表現,如果在子類中實現了父類的該方法,那么父類的該方法被重寫.
Override是調用父類方法的
5.error和exception的區別
error是不可預見的,一般是系統的錯誤.
exception是程序可以捕捉的異常.
posted on 2005-11-20 00:23 jame 閱讀(204) 評論(0) 編輯 收藏 所屬分類: JAVA基礎