+ 6
Is quiz in JAVA Challenge right?
I faced a quiz in JAVA Challenge "Finalized methods cannot be overriden", and the answer surprisingly was "false". Is that the right answer, and why? Thank you!
7 odpowiedzi
+ 7
That is because what you do when you override a method is to reallocate a new function to a specific method, exactly what the final keyword prevents.
+ 6
A final method cannot be overridden or hidden by subclasses.
https://en.m.wikipedia.org/wiki/Final_(Java)
+ 6
The wording is very important here. Final method is not the same as finalize method.
"The java.lang.Object.finalize() is called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup."
So yes, it can be overridden.
https://www.tutorialspoint.com/java/lang/object_finalize.htm
+ 2
Thank you, friends! I also think that finalized methods cannot be overriden. BUT!!! It was JAVA Challenge quiz and the answer was "false" in stead of "true". You can visit my profile on Sololearn and see screenshot of that quiz.
+ 2
Good point zemiak ,thanks for highlighting!
+ 1
Tibor Santa Oh my God! Thank you so much! I was overheating my brains for couple of days because of this. Great answer!
+ 1
notice, using of finalize() metod is deprecated
https://docs.oracle.com/en/java/javase/12/docs/api/java.base/java/lang/Object.html#finalize()