Class Test
{

public static void main(String [] args) throws Exception
{
try{
test();
}catch (IOException e) {
System.out.println("IOException thrown");
}catch(Exception e)
{
System.out.println("Exception thrown");
}
}

public static void test()
{
throw new IOException();
}

}

What would be the result?

Options
- The output is IOException thrown.
- The output is Exception.
- The code will not compile.
- The program will run normarlly.


CORRECT ANSWER : The code will not compile.

Discussion Board
test need to throw the exception

CORRECT ANSWER : The code will not compile.
because the Test class is not throws IOException. if it is like
public static void test() throws IOException
{
throw new IOException();
}
then code compile and give the output to IOException thrown

sanjay 05-4-2015 08:27 AM

Another reason for not compiling...

The class definition begins w/ 'Class' not 'class'. consider making the class keyword lower case.

Dwight Lillie 04-13-2015 05:20 PM

Checked Exception

Unhandled exception type IOExceptio - checked exception

Manish Malaviya 11-20-2014 06:12 AM

Write your comments


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)


Advertisement