Return to site

JAVA CERTIFICATION QUESTION: Initializing enums in Java code

· java

Given the following two Java types from a unit testing framework:

enum Outcome {
    SUCCESS, FAILURE;
    {System.out.print("IO ");}
    Outcome() {System.out.print("CO ");}
    static {System.out.print("SO ");}
}

class TestCase {  
    Outcome result;
    public TestCase() {
        System.out.print("CTC ");
    }
    { result = Outcome.SUCCESS; System.out.print("ITC ");}
}

And this test case scenario:

TestCase tc1 = new TestCase();
TestCase tc2 = new TestCase();

What will be the system output? Choose one.

A. IO CO SO CTC ITC CTC ITC

B. SO IO CO ITC CTC ITC CTC

C. ITC CTC ITC CTC SO IO CO

D. SO IO CO IO CO ITC CTC ITC CTC

E. IO CO IO CO SO ITC CTC ITC CTC

 

 

 

 

 

·Ǝ uoᴉʇdo sᴉ ɹǝʍsuɐ ʇɔǝɹɹoɔ ǝɥꓕ :uoᴉsnๅɔuoꓛ