To restate the same information that's already been presented:
1. Why are members of an interface always public?
It should be obvious why they are never private. Declaring a private interface is a meaningless statement. If you are "inside" a class, you can see what is private, and don't need any interface telling you what to do.
is only available to subclasses, defining a protected method in a class effectively imposes the interface that subclasses need to implement (if you define protected abstract
methods in an abstract class).
The only reason for an interface is to define a desired public interface to multiple unrelated classes. (there are actually other reasons - but their not applicable to your question)
2. Why is the finalize
All classes will have a finalize
method, but they cannot invoke the method on other classes. Indeed, they shouldn't invoke it on themselves either, but that can't be restricted by the interface. It will be invoked externally, and it can be overridden - in which case it should invoke super's implementation of it to correctly implement it.
(As noted above, if you are aware that an object is ready to be disposed of, it's best to clean up its resource use immediately rather than wait for any garbage collection cycle.)