What is the output of following code:

String s = "BIRD";
 
try {
    String x = "DOG";
    throw new Exception();
} catch (Exception e) {
    s = "CAT";
} finally {
    s = "GOAT";
    x = "FROG";
}

System.out.println(s);
Explanation
The x variable, declared in the "try" block is not visible in the "finally" block

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Cosmo
Sign Up Now
or Subscribe for future quizzes