Menu
Question Index
...

What will be the output of the following program?

public class FinallyFinalize {
    public static void main(String[] args) {
        A a = new A(1);
        a = null;
        a = new A(2);
        a = null;
        System.gc();
        try {
            Thread.sleep(-15);
        } catch (Exception ex) {
            System.out.print("E");
        }
        a = new A(3);
    }
}
class A {
    int i;
    public A(int i) {
        this.i = i;
        System.out.print("O" + i);
    }
    protected void finalize() throws Throwable {
        System.out.print("F" + i);
        super.finalize();
    }
}


O1O2EO3F2F1
O1O2F2F1EO3
O1O2F2F1O3
Some other output
Output can not be determined
Compilation Error or Runtime Error

Doubts

Problems

Topic: What is Multitasking and Multithreading?

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App