The IT Certification Resource Center

Featured Deal

Get CompTIA, Cisco, and Microsoft training courses free for a week.
Learn More ❯

Question 2:

What will happen when you attempt to compile and run the following code?

public class Static
{
    static
    {
        int x = 5;
    }
    static int x,y;
    public static void main(String args[])
    {
                x--;
        myMethod();
                System.out.println(x + y + ++x);
    }
    public static void myMethod()
    {
         y = x++ + ++x;
    }
}

A. Compile-time error
B. prints : 1
C. prints : 2
D. prints : 3
E. prints : 7
F. prints : 8