2014-04-26 18:59

题目:final、finally、finalize有什么区别?

解法:烂大街之java语法题。此题被多少公司考过我不知道,反正我确实遇见过一次了。

代码:

 1 // 14.3 final, finally and finalize, what are they?
 2 // you can't inherit me
 3 public final class TestJava {
 4     // you can't modify me
 5     public final int i = 123;
 6     public final int j;
 7     
 8     public TestJava () {
 9         j = 2;
10         // you can't modify me again.
11         // j = 3;
12     }
13     
14     // you can't override me
15     public final void f() {
16         System.out.println("TestJava.f()");
17     };
18     
19     // a substitute for ~TestJava().
20     // it signifies it is ready to be collected, but it doesn't have to be destroyed immediately.
21     @ Override
22     protected void finalize() {
23         System.out.println("finalized");
24     };
25     
26     public static void main(String[] args) {
27         TestJava testJava = new TestJava();
28         testJava.f();
29         testJava.finalize();
30     }
31 }

 

相关文章:

  • 2022-01-31
  • 2021-08-02
  • 2021-05-24
  • 2021-11-14
  • 2021-11-30
  • 2021-12-26
  • 2021-09-05
  • 2021-12-24
猜你喜欢
  • 2021-11-21
  • 2021-11-12
  • 2021-06-14
  • 2021-10-03
  • 2021-11-11
  • 2022-01-24
  • 2021-06-16
相关资源
相似解决方案