+ 1

What is the output of following code? Explain.

public class program { final int y; public static void main(String args[]) { final int x; y=3; x=6; System.out.print(x%y); } }

29th Aug 2017, 3:14 AM
shadab gada
3 Answers
+ 6
You'll get an error, because you can't access a non-static variable or method from a static method. once you change y to static it will output 0.
29th Aug 2017, 3:33 AM
ChaoticDawg
ChaoticDawg - avatar
0
Probably de running will failed because you need to declare the "y" inside the main method
29th Aug 2017, 3:35 AM
Sebastian Barreiro
Sebastian Barreiro - avatar
0
int x cannot be final, because it is a local variable that inside main method.
29th Aug 2017, 3:47 AM
Zeron
Zeron - avatar