| 1. |
What are variables? What are the rules to be followed while naming a variable. Give example. |
|
Answer» A variable is a placeholder for data that can change its value during program execution. Technically, a variable is the name for a storage location in the computer's internal memory. 1. Variable names can begin with either an alphabetic character, an underscore (_), or a dollar sign ($). However, convention is to begin a variable name with a letter. They can consist of only alphabets, digits, and underscore. 2. Variable names must be one word. Spaces are not allowed in variable names. Underscores are allowed. “total marks” is fine but “total marks” is not. 3. Variable Name must not be a reserved word. For example - int. 4. Java is a case-sensitive language. Variable names written in capital letters differ from variable names with the same spelling but written in small letters. int num1, num2, num3; |
|