Exceptions :
1.
public static int returnTest(){
try{
return 1;
}
catch(Exception e){
return 2;
} finally{
return 3;
}
}
What will returntest method return???
Ans : is 3.
If we have finally block it will always get called .
If we remove the finally block if will print 1.
2.
public class Test6
{
public static void main(String args[]) throws Exception{
try{
throw new Exception();
} finally{
System.out.println("No Error");
} }}
Here it will print No Error followed by java.lang.Exception.
Tuesday, May 27, 2008
Subscribe to:
Post Comments (Atom)


1 comment:
If we throw exception in method like
public void method()throws Exception{
throw new Exception();
}
It gives Runtime Exception.
Post a Comment