what is the use of finalize()Method
please explain with an example
Answer Posted / priyabrata patro
Once object is created than as java does not support delete keyword to delete the object , so , just imagine in our program when we create number of object than how it is deleted how memory occupied by this object recycled.
So,thankfully java supports gargage collector which is a program in jvm ,listen jvm is also a collection of program and garbage collector is one of them. Thus garbage collector is purely under cotrol of jvm .
So , now let us see what is the usage of finalize method .
When you go on creating the object , object occupies memory
and as memory is not infinite than you are prohibited to go on beyond the memory , but at that instance your program needs to have an object and memory is not available .So, there exactly we need finalize method to force garbage collector to recycle unused memory.
And you can say that as garbage collector is working why we need to use finalize method . As mentioned earlier that garbage collector is purely under control of jvm ,so jvm decides when it should work.okkk
| Is This Answer Correct ? | 8 Yes | 6 No |
Post New Answer View All Answers
Can we have multiple public classes in a java source file?
Why put method is used?
What is predicate in java?
Difference between comparator and comparable in java?
What do you understand by java virtual machine?
Can a set contain duplicates?
Does java allow default arguments?
Why can't we override private static methods?
What classes of exceptions may be thrown by a throw statement?
What is the difference between variable & constant?
What is the access scope of a protected method?
What are the string methods in java?
1.IN CASE OF DYNAMIC METHOD DISPATCH WHY WE USE REFERENCE VARIABLE,WE CAN USE THE DIFFERENT DEFINED OBJECT DIRECTLY TO ACCESS THE DATA MEMBER AND MEMBER FUNCTION OF THAT RESPECTIVE CLASS?WHAT IS THE MAIN FUNCTION OF "REFERENCE VARIABLE" HERE?
Can we write any code after throw statement?
What is the difference between preemptive scheduling and time slicing?