What is the result of compiling and running the following code (check all that apply)?

class ADaemon implements Runnable {
    public void run() {
        try {
            System.out.println("Running ADaemon");
            Thread.sleep(1);
        } catch (InterruptedException e) {
            System.out.println("Exiting with InterruptedException");
        } finally {
            System.out.println("Should this run in any case?");
        }
    }
}

public class DaemonsDontRunFinally {
    public static void main(String[] args) {
        Thread t = new Thread(new ADaemon());
        t.setDaemon(true);
        t.start();
    }
}
Explanation
All daemons are stopped "suddenly" when the last non-daemon stops. Thus after finishing execution of main() JVM immediately interrupts all daemons without following any formal rules.
If daemon was interrupted during a try-block, finally-block could have not been executed.

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Продовжуйте вивчати
тести з Java
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести