R

Rakesh Kumar • 28.44K Points
Instructor II

Q. 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();
      }
}

  • (A) One
  • (B) Two
  • (C) One Two
  • (D) One Two D. Compilation Error
  • Correct Answer - Option(C)
  • Views: 15
  • Filed under category JAVA

Explanation by: Rakesh Kumar
Finally block will execute irrespective of return statement in try block.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.


Question analytics