• 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
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Another mock question for Garbage Collection

 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From whizlabs,

Which of the following statements are true?
Select multiple options:


What's your answer for the questions?

Thank you.
 
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think

A) The finalize method is invoked by JVM at most once in the life of an object.
--- True.. because the garbage collection might never happen during the run time of an application at all or might happen . In first case finalize() method is never called, in second case its called just once per object.So yes the method is invoked at most once.

(B) If the finalize method is overriden, the JVM will definitely invoke it.
True...finalize method is over ridden so that you can perform final operations like closing connections stuff, just before garbage collection removes objects from memory.

(C) Exceptions thrown by the finalize method are ignored by the garbage collector.
True...the gc process continues, only the code in the finalize might be skipped after exception.

(D) Calling System.gc() will definitely call the finalize() method.
false...System.gc() can just request garbage collection, not gurantee it, so we cant guarantee that finalize() will run

(E) The finalize method may throw checked exceptions.
False...the defination of finalize does not throw checked exceptions...so while overriding it you cannot declare it to throw any checked exceptions either as per the overriding rule.
[ April 24, 2007: Message edited by: megha joshi ]
 
Sam Sunamin
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My Answer to it is A and
(A) True.
(B) If the finalize method is overriden, the JVM will definitely invoke it.
--False. Since JVM will not definitely invoke a finalize method.
(C)false, but I am not sure about this.
(D)false. Obvious.
(E)true. Since finalize() method in object throw Throwable. SO it can throw Exceptions.
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A,C,E are true,

By the way what is the score which you are getting in the whizlab mocks?
 
megha joshi
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I get why A and C are true.

But can you please elaborate on why E. is true?

Thanks!
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All is well but what goes wrong with this poor option!


(B) If the finalize method is overriden, the JVM will definitely invoke it.



Does anybody know?





Thanks,
cmbhatt
 
megha joshi
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I think this option is wrong becuase of the word "definately".

We know if the finalize() method is overridden it would be invoked by the JVM if garbage collection is started. But just as garbage collection is not definate, calling the finalize() is not definate and thus calling the overridden version of finalize() is not definate.

I think if the option would be like,

If the finalize() method is overridden, than the JVM can/may invoke it...
it would be more True.
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you sure Megha? Should I lock it?


Anyways good explanation!


Thanks,
cmbhatt
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by megha joshi:
Hi,

I get why A and C are true.

But can you please elaborate on why E. is true?

Thanks!



This is because finalize in defined as
protected void finalize() throws Throwable.

And since it can throw throwable it can definitely throw Exception which is a subclass of Throwable.
 
sharan vasandani
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
exactly
 
Sam Sunamin
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I only get 73% of the practice 4, and I did not do the final mock yet. The first three practice, I get really low score.

So I think I may pass the exam with low score. I don't have too much time to prepare the exam.

Megha 's explain for C is reasonable.B is wrong because of "Definitely".

Thank you for all your reply.
[ April 25, 2007: Message edited by: Sam Sunamin ]
 
I knew I would regret that burrito. But this tiny ad has never caused regrets:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic