This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes finalize access specifiers public/protected/private Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "finalize access specifiers public/protected/private" Watch "finalize access specifiers public/protected/private" New topic

finalize access specifiers public/protected/private

Siva kandasamy
Ranch Hand

Joined: Dec 31, 2002
Posts: 139
Hi There,
Refer the example #1 "" Change the finalize method with following piece of code
void finalize(){
private void finalize(){

The question is, If you do change, you will get compilation error.
Please help me to understand, why do we get compilation error, if we use access specified other than public or protected.
Hope my posting make sense.
Thanks in Advance

*********** Example #1 **************************

class TestA {
void Hello(){

protected void finalize(){
class Finalize {

public static void main(){
Deep Chand
Ranch Hand

Joined: Dec 17, 2002
Posts: 133
Hi Sivanantham ,
"protected void finalize()" is a method in Object class, which is a superclass of every class.
The access specifier in a method that overrides a method in the super class should be same or more than than access in the method in the super class. So the finalize() method in your class can be protected or public. It can't be package or private.
Consider Paul's rocket mass heater.
subject: finalize access specifiers public/protected/private