public class RecursionDemo
public static void main(String args)
1.Compile Error 2.Runs continuously forever 3.Exception 4.None
The program compiles, and during execution, StackOverFlow error occurs, because whenever a method is invoked, an entry is created on stack, hence continuously a method invokes itself, and entries keep on getting added to stack.A method calling itself is called as Recursion. Due to this Stack get filled up, and StackOverFlowError exception occurs. Since this is Run time exception, this need not be handled with try catch blocks.
You may also like to read: Exception handling
Below is difference between final, finally and finalize() is entirely different.
final and finally are keywords.finalize is a method.
is a keyword, which is used for below purpose
1. To declare constants.
2. To define final class.
3. To declare final methods.
is a keyword, which is used in exception handling. finally block can exist only along with try and catch block. code enclosed in finally block gets executed irrespective of exception occurring or not.
is method actually declared in Object class(which is base class of all classes in Java). This method can be overridden by any class, for garbage collection purpose.The java run time calls this method whenever it is about to recycle an object of the class