The IT Certification Resource Center

Featured Deal

Get CompTIA, Cisco, and Microsoft training courses free for a week.
Learn More ❯

Question 9:

What is the result when you compile and run the following code?

public class ThrowsDemo 
{  
    static void throwMethod() 
    {  
        System.out.println("Inside throwMethod.");  
        throw new IllegalAccessException("demo");  
    }
  
    public static void main(String args[]) 
    {  
        try 
        {  
            throwMethod();  
        } 
        catch (IllegalAccessException e) 
        {  
            System.out.println("Caught " + e);  
        }  
    }  
}
A. Compilation error
B. Runtime error
C. Compile successfully, nothing is printed
D. Inside throwMethod. followed by caught: java.lang.IllegalAccessExcption: demo