what are the differences between final,finally,finalize
methods?
Answer Posted / jayakrishnan.p
final is used for making a class no-subclassable, and making
a member variable as a constant which cannot be modified.
finally is usually used to release all the resources
utilized inside the try block. All the resources present in
the finalize method will be garbage collected whenever GC is
called. Though finally and finalize seem to be for a similar
task there is an interesting difference here.This is because
the code in finally block is guaranteed of execution
irrespective of occurrence of exception, while execution of
finalize is not guarenteed.finalize method is called by the
garbage collector on an object when the garbage collector
determines that there are no more references to the object.
Is This Answer Correct ? | 168 Yes | 17 No |
Post New Answer View All Answers
Why 1 is not a prime number?
Say you want to store the information about a number of pets in an array. Typical information that you could store for each pet (where relevant) would be • Breed of animal • Animal's name • Its birth date • Its sex • Whether it has been sterilised or not • When it is due for its next inoculation • When it last had its wings clipped For each type of pet (eg. dog, cat or bird) you would typically define a class to hold the relevant data. Note: You do not need to implement these classes. Just answer the following questions. 3.1.1 What would be the advantage of creating a superclass (eg. Pet) and declaring an array of Pet objects over simply using an array of Objects, storing each of the instances of the different pet classes (eg. Dog, Cat or Bird) in it? 3.1.2 Would you define Pet as a class or as an interface? Why? (2) (2)
Can constructor be synchronized?
If I only change the return type, does the method become overloaded?
how are methods defined?
How does remove work in java?
What are format specifiers in java?
What is the importance of hashcode() and equals() methods?
Can an interface extend another interface?
Can we initialize the final blank variable?
Can we override singleton class?
How many bytes is a string?
Explain about anonymous inner classes ?
How to compare strings in java?
How do you convert string to int in java?