2018年3月2日 星期五

Legal Identifiers

Technically, legal identifiers must be composed of only Unicode characters, numbers, currency symbols, and connecting characters (like underscores). The exam doesn't dive into the details of which ranges of the Unicode character set are considered to qualify as letters and digits. So, for example, you won't need to know that Tibetan digits range from \u0420 to \uOf29. Here are the rules you do need to know:
  • Identifiers must start with a letter, a currency character ($), or a connecting character such as the underscore ( _ ). Identifiers cannot start with a number!
  • After the first character, identifiers can contain any combination of letters, currency characters, connecting characters, or numbers.
  • In practice, there is no limit to the number of characters an identifier can contain.
  • You can't use a Java keyword as an identifier.
  • Identifiers in Java are case-sensitive; foo and Foo are two different identifiers.

Examples of legal and illegal identifiers follow, first some legal identifiers:

int _a;
int $c;
int ______2_w;
int _$;
int this_is_a_very_detailed_name_for_an_identifier;

The following are illegal (it's your job to recognize why):

int :b;
int -d;
int e#;
int .f;
int 7g;

Given:

35. String #name = "Jane Doe"; 
36. int $age = 24; 
37. Double _height = 123.5; 
38. double ~temp = 37.5; 

Which two statements are true? (Choose two.)

A. Line 35 will not compile.
B. Line 36 will not compile.
C. Line 37 will not compile.
D. Line 38 will not compile.

沒有留言:

張貼留言