What is the output of the following Java program A11?

Description:

public class Main{  
     public static void main(String []args){  
        try  
        {  
            throw 90;   
        }  
        catch(int e){  
            System.out.println("Caught the exception "+e);  
        }  
            
    }  
}  

Solution:

Output

Main.java:6: error: incompatible types: int cannot be converted to Throwable
            throw 90; 
            ^
Main.java:8: error: unexpected type
        catch(int e){
              ^
  required: class
  found:    int
2 errors

Explanation

In Java, the throwable objects can only be thrown. If we try to throw an integer object, The compiler will show an error since we can not throw basic data type from a block of code.

0 answers