posted 17 years ago
The finalize method is intended to be executed by the JVM just before GC collects garbage.
What is the minimum accessibility you could give to a method so that it could be overriden by any other sublass of object?
The answer is: protected.
You can override the method and do it public if you want, however, according to the contract of the finalize method, it would not make any sense.
A method is public if you pretend to offer some service through it, but no other class or object should invoke finalize directly. It should only be invoked by JVM before garbage collection.
Then, the best you can do is declare it protected.
Why?, well, If you do it private, it cannot be overriden, if you do it package accessible it cannot be overriden by classes in other packages. If you do it public, well, we already talked about it.
Then the best option is to make it protected.
Does that sound logical to you?