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 (and several other programming languages), integer literals starting with 0 are interpreted as octal (base-8) numbers, not decimal. The literal '010' in octal equals 8 in decimal (1×8¹ + 0×8⁰ = 8). Therefore, when the code prints 'X=' + x, it outputs 'X=8'. This is a common trick question testing knowledge of octal notation in programming languages.