Java Specialists' Java Training Europehome of the java specialists' newsletter

The Java Specialists' Newsletter
Issue 083b2003-12-26 Category: Language Java version:

GitHub Subscribe Free RSS Feed

End of Year Puzzle Follow-up

by Dr. Heinz M. Kabutz

Hi again,

A great number of subscribers are on holiday at the moment, but to those that are not, thanks for sending your answer to the puzzle. Approximately 70% of respondents had the correct answer, which either means that the puzzle was way too easy, or that the correct answer was also the most obvious one.

As a short follow-up, here is a variation of the puzzle for your amusement.

What is the output of the following Java snippet?

public class Puzzle3 {
  public int test() {
    int i = 0;
    try {
      return i;
    } finally {
      return i;
  public static void main(String[] args) {
    Puzzle3 p = new Puzzle3();

And here is the multiple choice again:

  1. The code does not compile
  2. The code compiles, but throws an exception
  3. The code prints "0"
  4. The code prints "1"
  5. The code prints "2"
  6. None of the above
  7. All of the above

I expect the split between correct/incorrect to be similar to the previous "puzzles", since the question is so similar.

Kind regards


Language Articles Related Java Course

Extreme Java - Concurrency and Performance for Java 8
Extreme Java - Advanced Topics for Java 8
Design Patterns
In-House Courses

© 2010-2016 Heinz Kabutz - All Rights Reserved Sitemap
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners. is not connected to Oracle, Inc. and is not sponsored by Oracle, Inc.