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
Java
Java Quiz
Start Quiz

or Read more about Java Quiz

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback