http://yoyo08.javaeye.com/blog/556602文章来源 1. final 用于声明属性,方法和类,分别表示属性不可变,方法不可覆盖,类不可继承。( 注意:如果是基本类型,说明变量本身不能改变;如果是引用类型,说明它不能指向其他的对象了,但对象还是可以改变的。) 2. finally是异常处理语句结构的一部分,表示无论是否出现异常总是执行。 3. finalize是Object类的一个方法,在垃圾收集器执行的时候会调用被回收对象的此方法,可以覆盖此方法提供垃圾收集时的其他资源回收,例如关闭文件等。 Java代码 1. public class Test 2. { 3. private int a = 2; 4. 5. public static void main(String[] args) 6. { 7. final Test t = new Test(); 8. Test tt = new Test(); 9. 10. // t = tt; //错误 11. 12. t.a = 6; 13. System.out.println(t.a); 14. 15. final int b = 1; 16. final int c = 2; 17. int d = 3; 18. 19. // b = c; //错误 20. // b = d; //错误 21. } 22. } public class Test { private int a = 2; public static void main(String[] args) { final Test t = new Test(); Test tt = new Test(); // t = tt; //错误 t.a = 6; System.out.println(t.a); final int b = 1; final int c = 2; int d = 3; // b = c; //错误 // b = d; //错误 } }
java 中 finial finally 和 finanize的区别
最新推荐文章于 2022-12-12 21:13:30 发布