मराठी

What are the rules for naming a variable in JAVA?

Advertisements

प्रश्न

What are the rules for naming a variable in JAVA?

सविस्तर उत्तर
Advertisements

उत्तर

  1. Valid Characters: A variable name can contain letters (A–Z, a–z), digits (0–9), underscores (_) and dollar signs ($).
  2. Starting Character: A variable name must begin with a letter, underscore (_) or dollar sign ($). It cannot begin with a digit.
  3. No Spaces: A variable name cannot contain spaces.
  4. No Special Symbols: Special symbols such as @, #, %, & and - are not allowed in variable names.
  5. Case Sensitivity: Java is case-sensitive. Therefore, age, Age and AGE are treated as different variables.
  6. No Reserved Keywords: Java keywords such as int, class, public and static cannot be used as variable names.
  7. Meaningful Names: Variable names should be meaningful and indicate the purpose of the variable.

Examples:

  • Valid Variable Names: studentName, totalMarks, age1, _count
  • Invalid Variable Names: 1age, student name, class, total-marks
shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 6: Variables and Expressions - EXERCISE [पृष्ठ १३१]

APPEARS IN

धीरज मेहरोत्रा Computer Science [English] Class 12
पाठ 6 Variables and Expressions
EXERCISE | Q 8. | पृष्ठ १३१
Advertisements
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×