Hello RajTilaK,
Yup my doubt is that in the program flow gc() has finalize method in it but why id finalize method of string class called because in this case string class is not child class but still why string class finalize() method called
best way to call finalize() is with try-catch block, where any exception is assumed to handle, along with finally block if externally you wish to call finalize()of object.
String class doesnt have any finalize() method and, there is no guarantee of forced call to gc() runs GC - it depends upon JVM only
so, if JVM calls GC, finalize() gets called automatically but here, in your code, there is no way to call the overriden method within the class so it is not getting called.