exceptions

Quiz Guidelines

 

Descriptive Question

QID: 
55

Based on assumptions and facts, find the output.

Assumption: filename.txt does not exist.

Fact: FileNotFoundException is a child of IOException.

Program:
 

    try {

      File file = new File("filename.txt");

      Scanner sc = new Scanner(file);

      throw new IOException();

    } catch (IOException e) {

      System.out.println("IOException called!!!");

    } catch (FileNotFoundException e) {

      System.out.println("FileNotFoundException called!!!");

    }

 

Descriptive Question

QID: 
50

Predict output:

public class ExceptionCheck {

	static int i = 10;

	public static void main(String[] argds) {
		System.out.println(myMethod());
		System.out.println(i);
	}

	public static int myMethod() {
		try {
			throw new RuntimeException();
		} finally {
			i = 12;
		}
	}
}

 

Multiple Choice Question

QID: 
33

Given:

public class ExceptionCheck {
	
	static int i = 10;
	
	public static void main (String[] argds)
	{
		System.out.println(myMethod());
		System.out.println(i);
	}
	
	public static int myMethod()
	{
		try{
			throw new Exception();
		}
		catch(Exception e)
		{
			return i;
		}
		finally{
			i = 12;
            return i;
		}
        return i;
	}
}

 

Select 1 option

A. Compilation Fail

B. Print 10 and 12.

C. Print 10 and 10.

D. Print 12 and 12.

Multiple Choice Question

QID: 
32

Given:

public class ExceptionCheck {
	
	static int i = 10;
	
	public static void main (String[] argds)
	{
		System.out.println(myMethod());
		System.out.println(i);
	}
	
	public static int myMethod()
	{
		try{
			throw new Exception();
		}
		catch(Exception e)
		{
			return i;
		}
		finally{
			i = 12;
            return i;
		}
	}
}

 

Select 1 option

A. Compilation Fail

B. Print 10 and 12.

C. Print 10 and 10.

D. Print 12 and 12.

Multiple Choice Question

QID: 
31

Given:

public class ExceptionCheck {
	
	static int i = 10;
	
	public static void main (String[] argds)
	{
		System.out.println(myMethod());
		System.out.println(i);
	}
	
	public static int myMethod()
	{
		try{
			throw new Exception();
		}
		catch(Exception e)
		{
			return i;
		}
		finally{
			i = 12;
		}
	}
}

 

Select 1 option

A. Compilation Fail

B. Print 10 and 12.

C. Print 10 and 10.

D. Print 12 and 12.

Search the Web

Custom Search

Searches whole web. Use the search in the right sidebar to search only within javajee.com!!!