Tricky Java Program

What will be the output of this?

public class Test {

static int something(int i){

return 22;
} finally{
return 25;
public static void main(String s[]){


What will the method return? There are two return statements :)
25 is the answer as the code within finally will execute no matter what. If you comment the return statement in the finally block then 22 will be returned. A tricky interview question and many may think this wont even compile. A method can have two return statements!(without if/else block).

Difference between NoClassDefFoundException and ClassNotFoundException

A NoClassDefFoundException is thrown during runtime if an object of a class created with the new() operator (static loading) cannot be found during runtime. This can happen due to many reasons:
1) You created a public class but did not save it with the right name. You will be able to compile it but not run it.
2) You did not include the class/jar in the classpath.

A ClassNotFoundExceptionis a checked exception thrown at runtime when you try to load a class using Class.forName() method. The String arguments to that method should contain a fully qualified class name and the class should be valid and included in the classpath. The best example is during a JDBC connectivity. To connect using JDBC you load the class at runtime using Class.forName(“com.mysql.jdbc.driver”). But if the MySQL connectivity mysql-connector-java.jar (which contains the driver class) cannot be found in the classpath then ClassNotFoundException will be thrown.