Facebook

adsense

Tuesday, 28 April 2015

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

                            <  PREVIOUS || Main Page || NEXT  >
Give your answer in the comment below

No comments:

Post a Comment