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
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
1
Answer:
compile time error
Explanation:
Cannot make static reference to non-static field.
Similar questions
Math,
1 month ago
Social Sciences,
1 month ago
Social Sciences,
1 month ago
Math,
2 months ago
Math,
9 months ago
Science,
9 months ago