JAVA

Constants and Variables

Constants

Constants Constants are declared with keyword final. Their values cannot be changed during program execution. For example:

final double PI = 3.1415926; // Need to initialize

Note:

A final local variable that has been declared but not yet initialized is called a blank final.


Variables

A variable is used to store a piece of data for processing. It is called variable because you can change the value stored.

A variable is a named storage location, which stores a value of a particular data type. In other words, a variable has a name, a type and stores  a value of that type.

A variable has a type. A variable can store a value  of that particular type.

int x = 100;
short y = 5;
float z = 365.24;



Subscribe us on Youtube

Share This Page on


Ask Question