English

Differentiate between the following: Constant and Variable

Advertisements

Question

Differentiate between the following:

Constant and Variable

Distinguish Between
Advertisements

Solution

Constant

Variable

1. A constant is a value that cannot be changed during the execution of a program.

1. A variable is a named memory location whose value can be changed during the execution of a program.

2. A constant is declared using the final keyword in Java.

2. A variable is declared by specifying its data type and name.

3. Once a constant is assigned a value, it cannot be reassigned.

3. The value of a variable can be modified whenever required during program execution.

4. Constants are used to store fixed values that remain unchanged throughout the program.

4. Variables are used to store data values that may change during program execution.

5. Example: final int MAX = 100; Here, the value of MAX cannot be changed.

5. Example: int age = 18; Here, the value of age can be changed.

shaalaa.com
  Is there an error in this question or solution?
Chapter 6: Variables and Expressions - EXERCISE [Page 132]

APPEARS IN

Dheeraj Mehrotra Computer Science [English] Class 12
Chapter 6 Variables and Expressions
EXERCISE | Q 30. (a) | Page 132
Advertisements
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×