This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread 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 Murach's Java Servlets and JSP this week in the Servlets 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.
It is sorta covered in the JavaRanch Style Guide.
subject: finalize access specifiers public/protected/private
Similar Threads
Protected Access Confusion
What is the Prototype for Main method in java
finalize access specifiers protected/private/public
Why Compiler error?.....