I am putting two questions in which we have return statement in one question after try block and in the second question it is after catch block. Please explain me what the return does in try/catch block.
Question: 1
What is the O/P of the following try...catch block
public class fun
{
public static void main(
String args[])
{
try
{
int i;
return;
}catch(Exception e)
{
System.out.println("Hi everybody!");
}finally
{
System.out.println("We love Java");
}
}
}
a. Hi everbody!
b. We love
Java c. No Output
d. Depends on the creation of int i
Answer: b
*****************************************************************
Question : 2
Consider the following code fragments.
try{
URL u=new URL(path);//assume path is a previously defined String
Object obj=in.readObject();// in is a valid ObjectInputStream
System.out.println("Success");
}
catch(MalformedURLException e){
System.out.println("Bad URL");
}
catch(StreamCorruptedException e){
System.out.println("Bad File Contents");
}
catch(Exception e){
System.out.println("General Exception");
}
finally{
System.out.println("Finally Part");
}
System.out.println("Carrying On");
What lines are output if the code at the second line throws a MalformedURLException. Choose all valid answers.
a. Success
b. Bad URL
c. Bad File Contents
d. General Exception
e. Finally part
f. Carrying On
Ans: b,e and f
Please expalin .
--Shallender