Computer Science, asked by meghasharma2905, 2 months ago

What is the output of following Java Program?

class Test {

int x = 10;

public static void main(String[] args) {

System.out.println(x);

}

}


Select one:
Compile Time Error
10
0
Runtime Exception​

Answers

Answered by BrainlyProgrammer
10

Answer:

  • OPTION A: Compile Time Error

Reason:-

  • Cannot make static reference to non-static field.
  • You should create an object in order to access the class variable 'X' then only you can remove this error.
  • Example,

Test ob=new Test();

System.out.println(Test.x);

//now error is removed and finally, x will be printed.

Answered by aniketsingh0305
1

Answer:

compile time error

Explanation:

Cannot make static reference to non-static field.

Similar questions