Submitted by heartin on Sat, 10/31/2015 - 19:53
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!!!");
}
Submitted by heartin on Fri, 10/09/2015 - 20:44
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;
}
}
}
Submitted by heartin on Sat, 09/12/2015 - 22:43
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.
Submitted by heartin on Sat, 09/12/2015 - 22:42
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.
Submitted by heartin on Sat, 09/12/2015 - 22:42
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.