Top

Discussion

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.00
  • B.1
  • C.2
  • D.Compilation fails

Answer: D

Compilation failed because static was an illegal start of expression - method variables do not have a modifier (they are always considered local).

No comment is present. Be the first to comment.
Loading…

Post your comment