?
What will be the output?
What will be the output?
class MyClass{
public String test(){
try{
System.out.print("One");
return "";
}
finally{
System.out.print("Two");
}
}
}
public class Test{
public static void main(String args[]){
MyClass m = new MyClass();
m.test();
}
}
class MyClass{
public String test(){
try{
System.out.print("One");
return "";
}
finally{
System.out.print("Two");
}
}
}
public class Test{
public static void main(String args[]){
MyClass m = new MyClass();
m.test();
}
}
Answer & Solution
Correct Answer:
Option
C
Finally block will execute irrespective of return statement in try block.
Join the Discussion
Login to post a comment or share your explanation.
Loginprogram will execute successfully because there is no exception in try block so there is no need of catch block to handle any exception and finally will always executed with or without try and catch block.