Computer Science, asked by disha246867, 1 day ago

Identify the following variables as valid or invalid: a. If b. True c. NUM21 d. 21_NUM​

Answers

Answered by shreyasi1157
1

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:-
  1. byte
  2. short
  3. int
  4. long
  5. float
  6. double
  7. string
  8. boolean
  9. final
  10. finally
  11. public
  12. class
  13. private
  14. void
  15. protected
  16. for
  17. if
  18. 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...

Similar questions