Multiple choice

Which of following are legal Java identifiers?

  1. 2answer

  2. maybe

  3. foo+bar

  4. can't_decide

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

A legal Java identifier must begin with a letter, underscore (_), or dollar sign ($), and cannot contain operators or special characters like '+' or apostrophes. 'maybe' is a perfectly legal identifier, whereas '2answer' starts with a digit, 'foo+bar' contains an addition operator, and 'can't_decide' contains an apostrophe.