Ch2 Java Building Blocks Flashcards

1
Q

An identifier is the name of a variable, method, class, interface, or package. There are 4 rules for legal identifiers. What are they?

A
  • Identifiers must begin with a letter, a $ symbol, or a _ symbol.
  • Identifiers can include numbers but not start with them.
  • A single underscore _ is not allowed
  • A java reserved word is not allowed (case sensitive)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Does the following code compile?

public void test() {
var n = “hello”;
n = null;
var m = 1;
m = null;
}

A

It does not compile because the type for m is an int and a primitive int cannot be assigned null.
n = null compiles fine.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly