Question: I am new to Java language and cannot understand the behavior of finally block in this program. This program should exit after printing BC whereas it is printing BCD. Please help. 

```
class Main 
{  
    public static void main(String [] args) 
    {
        try 
        {
            badMethod();  
            System.out.print("A"); 
        }  
        catch (Exception ex) 
        {
            System.out.print("B");  
        } 
        finally 
        {
            System.out.print("C"); 
        } 
        System.out.print("D"); 
    }  
    public static void badMethod() throws Exception
    {
        throw new Exception(); /* Line 22 */
    } 
}

```

Answer: 
The `finally` block doesn't finalize the program, it just ensure to execute every time the try catch block runs whereas there is an exception or not..
Finally is the must executable block of java program.
It allows all the allocated resources of the currently running program to get free and make it available for the other applications if required.

This is mainly used when we share the common resources like Database or the devices.