If you are more advanced, then finalize() is supposed to be called by the JVM, not from any of your classes at all, so it ought not to be public. If it had private or default access, then it would be impossible to override, so it must have protected access.
not from any of your classes at all, so it thought not to be public
hello sir... Even though it is protected all class can overide the method because every class is a sub class of Object class .Then what sort of difference will exists between Protected and public in this issue. protected in the sence only sub class can view public in the sence all classes can view .here even though my class is not extending the object class compiler by default extend the object class.
In terms of Object and finalize(), this means that code in any class C can call finalize() on its own instances, and super.finalize(), but that's it -- it can't call finalize on instances of any other class.
This is perfectly in line with the intended purpose of finalize(). Only the system is supposed to call it, but you need to be able to call super.finalize() if you override it. you should never try to call it on any other class.
Ernest Friedman-Hill wrote: P defines a protected method m(). Code in C1 can, of course, call m() on instances of P and on instances of C1 itself. But code in C1 can not call m() on instances of C2!
I think code in c1 can call m() on instances of c2 in the same Package.
If Packages are different
Code in C1 can, cannot, call m() on instances of P . and also code in C1 cannot call m() on instances of C2!
Please clear my speculation on that