1. 

What will be the output of the program?

public class Test 
{  
    public static void main(String args[])
    { 
        class Foo 
        {
            public int i = 3;
        } 
        Object o = (Object)new Foo();
        Foo foo = (Foo)o;
        System.out.println("i = " + foo.i);
    }
}

A. i = 3
B. Compilation fails.
C. i = 5
D. A ClassCastException will occur.

2. 

What will be the output of the program?

public class A
{ 
    void A() /* Line 3 */
    {
        System.out.println("Class A"); 
    } 
    public static void main(String[] args) 
    { 
        new A(); 
    } 
}

A. Class A
B. Compilation fails.
C. An exception is thrown at line 3.
D. The code executes with no output.

3. 

What will be the output of the program?

class Super
{ 
    public int i = 0; 

    public Super(String text) /* Line 4 */
    {
        i = 1; 
    } 
} 

class Sub extends Super
{
    public Sub(String text)
    {
        i = 2; 
    } 

    public static void main(String args[])
    {
        Sub sub = new Sub("Hello"); 
        System.out.println(sub.i); 
    } 
}

A. 0
B. 1
C. 2
D. Compilation fails.

4. 

What will be the output of the program?

public class Test 
{
    public int aMethod()
    {
        static int i = 0;
        i++;
        return i;
    }
    public static void main(String args[])
    {
        Test test = new Test();
        test.aMethod();
        int j = test.aMethod();
        System.out.println(j);
    }
}

A. 0
B. 1
C. 2
D. Compilation fails.

5. 

What will be the output of the program?

interface Count 
{
    short counter = 0;
    void countUp();
}
public class TestCount implements Count 
{
    public static void main(String [] args) 
    {
        TestCount t = new TestCount();
        t.countUp();
    }
    public void countUp() 
    {
        for (int x = 6; x>counter; x--, ++counter) /* Line 14 */
        {
            System.out.print(" " + counter);
        }
    }
}

A. 0 1 2
B. 1 2 3
C. 0 1 2 3
D. 1 2 3 4