Explain final, finalize() and finally?

Answer Posted / zama

final keyword are assigned to 3 different things such as
(1)___to variables:
if the variable is declared as final then value to
that variable can be assigned only once.
(2)___to methods:
if the method is declared as final then method cannot
be overridden.
(3)___to class:
if class is declared as final then class cannot be
inherited.



if finally block is defined in the main() then the stmt
under it will be executed surely,but if the stmt
System.exit(0); is before finally block then it is not executed.



finalize():
finalize() method is called by the Garbage
Collector on an object when there is no more reference to
the object.
finalize() is never run more than once on any object.

Is This Answer Correct ?    5 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is local variable and instance variable?

599


What is object cloning in Java?

625


Discuss 2D arrays.

597


In java, how we can disallow serialization of variables?

544


What is anti pattern in cyber security?

511






why would you use a synchronized block vs. Synchronized method? : Java thread

526


What is java object name?

543


What if the main() method is declared as private? What happens when the static modifier is removed from the signature of the main() method?

674


Why hashcode is used in java?

492


Which collection is sorted in java?

538


In how many ways we can create threads in java?

619


Can this keyword be used to refer static members?

540


What is method overriding in java ?

646


Do you know why doesn't the java library use a randomized version of quicksort?

542


What all methods are used to prevent thread execution ?

543