• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

finalize() ?

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which of the following are true ? Select six answers?

1. The signature of finalize() method is, protected void finalize() throws Throwable{}

2. The signature of finalize() method is, public void finalize() throws Throwable {}

3.The signature of finalize() method is, void finalize() throws Throwable {}

4.The signature of finalize() method is, private void finalize() throws Throwable {}

5.The finalize() method can be Overloaded.

6.The throws clause of the finalize() method can be defined with any exception.

7.The finalize() method is guaranteed to be called on any object to be GC'ed.

8.The finalize() method is called only once on any object to be GC'ed.

9.There is no restriction on the number of times the finalize() method is called on an object to be GC'ed.
test says that 1,2,5,6,7,8 is correct answers. Why 2 is correct?
thanx to all.
 
Sheriff
Posts: 17734
302
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because the "(Java) Bible" says so... see http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html#finalize()
Edit:
Just noticed that Object declares finalize() as protected. Hmmmm... must look into this further... Haven't found anything in JLS yet so if Cindy or anybody else doesn't clear this up first, I'll get back to you later.

------------------
Junilu Lacar
Sun Certified Programmer for the Java� 2 Platform
[This message has been edited by JUNILU LACAR (edited November 10, 2001).]
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree 100% with 1, 5, 7 and 8
for 2 and 6 the questios are not well worded. They refer no to the finalize method in the Object class. But any overriding finalize method. When overriding a member you can increase the access, but not decreasing it.
 
Andrey Opanasets
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JUNILU

Java Bible says next:
protected void finalize() throws Throwable;
Why "public void finalize() throws Throwable;" is correct signature?
test from www.jtips.net Mock1
thanx

[This message has been edited by Andrey Opanasets (edited November 10, 2001).]
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can make a method to be more accessible (protected to public) but not the opposite, i.e.
private void finalize() throws Throwable;
is not valid.
HIH
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys...Check this link out...
http://www.javaranch.com/ubb/Forum24/HTML/012910.html

HTH
Shyam
Sun Certified Programmer for the JavaTM2 Platform
[This message has been edited by Shyamsundar Gururaj (edited November 11, 2001).]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic