Identify the following variables as valid or invalid: a. If b. True c. NUM21 d. 21_NUM
Answers
Explanation:
(a) Invalid
Because if is a keyword in java and keywords cannot be used as variable names
(b) Valid
(c) Valid
(d) Invalid
Because variable name cannot start with any digit.
Note:-
RULES OF WRITING VARIABLES IN JAVA:-
1) Variables never start with any digit.(14ST - wrong)
2) White space is not allowed( Number 1 - wrong Number1- correct
3) Special characters are not allowed.
=> Only 2 special characters you can use,i.e.
- Dollar($)
- Underscore(_) -----> total_mark- correct
abc$- correct
abc#- wrong
=> User can declare the special character at any position( beginning, mid, end) ------> _x - correct
a$bc- correct
4) Java keywords cannot be used as variable names.
- Few examples of keywords:-
- byte
- short
- int
- long
- float
- double
- string
- boolean
- final
- finally
- public
- class
- private
- void
- protected
- for
- if
- else, etc.
5) Variable can contain uppercase character or lower case character or both. ------> SUM - correct
sum - correct
Sum - correct
Hope it helps....
PLEASE MARK ME AS BRAINLIEST AND DON'T FORGET TO FOLLOW ME...