Hi guys What happens if I override the finalize method present in the Object class and create a new instance of the object in the finalize method. Sample code given below
I still do not understand the use of this method. If you creating a new object inside the finalize. This object will be available for GC again in this new object GC will call the finalize method which creates another new object. But this goes on util the JVM will exist. So basically the GC is going in loops. for removing one single object. This is my conclusion from this code.
I do not know if this is correct or not. Comments and suggestions are welcome.
Well guys here is what happens. Nothing will happen. The GC will not go in a loop nor the JVM will crash. As per the rules of GC the program will exit normally. Here is the link from Java Forums by Sun. that explains it clearly