Declarations and Access Control

Q1: 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 Compilation fails.

B 1

C 2

D 0

ANS:A - 0

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



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.