Multiple choice general knowledge history

public class Question { public static void main(String args[]) { int x=010; System.out.print("X="+x); } }

  1. X=8

  2. X=10

  3. X=11

  4. None

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

In Java, when you write 'int x=010;', the leading zero makes it an octal literal. Octal 010 equals decimal 8 (1*8^1 + 0*8^0 = 8). So the output is 'X=8'.