1.异常的限制 当覆盖方法的时候,仅仅能抛出在基类方法的异常说明里列出的那些异常. 这意味着,当基类使用的代码应用到其派生类对象的时候,一样能够工资,异常也不例外. 以下的样例是在编译时施加在异常上面的限制: public class BaseBallException extends Exception {} public class Foul extends BaseBallException{} public class Strike extends BaseBallException{}
final关键字类似const: import java.util.*; public class FinalData { static Random rand = new Random(47); final int valueOne = 9; final int i4 = rand.nextInt(20); static final int INT_5 = rand.nextInt(20); public static void main(String[] args) { FinalData
本章提到的关于==的部分,一个完整的实验如下: class Test { public static void main(String[] args) { Integer i = new Integer(47); Integer j = new Integer(47); Integer i1 = 47; Integer j1 = 47; int i2 = new Integer(47); int j2 = new Integer(47); int i3 = 47; int j3 = 47; Sy
java对于将一个较大作用域的变量“隐藏”的场景会有保护:编译告警.比如: int x = 5; { int x = 6; } 但是对于类中方法的局部变量和类成员变量确是可以重名的,比如 class Test { int x = 4; String s = "hello"; void show() { int x = 5; System.out.println(this.x); System.out.println(x); System.out.println(s); } public