Out of curiosity,
Why is the finalize() method\'s access modifier is made as protected. Why cant it be public? Can someone exp
Also, I came to know that finalize() method is called only once. If i call it twice in my program, internally what is happening?
You probably ask this under impression of C++ ~destructors. In java finalize () method doesn't do any magic (like clearing memory). It's supposed to be called by garbage collector. But not vice versa.
I recommend you to read correspondent chapter in Joshua Bloch's "Effective Java". It says that using finalizers is a bad practice and can cause performance and other issues, and there are only several cases when they should be used. The chapter begins with next words:
Finalizers are unpredictable, often dangerous, and generally unnecessary.