elibraryportal Logo

Variable in Java

  • Every variable is assigned a data type which store the value of variable..
  • Variables are containers for storing data values..
  • Variables, store a value in a variable when can be changed during program execution.
Variable in Java

type :- Where type is the data type that can be stored in variable.

name : - Where name is the given by user to the variable.


Types of Variable :

There are three types of variables in Java that is...

  1. Local Variable
  2. Instance Variable
  3. Static Variable

1) What is Local Variable

A Local variables is declare inside the method or block or constructor is called local variable.

Example

Output

What is Local Variable

2) What is Instance Variable

Instance Variable declared inside the class but outside the method.

Example

Output

What is instance Variable

3) What is Static variable

  • Static variables are also known as Class variables.
  • Static is a keyword in Java, that is manily used for memory management.
  • We can use static keyword with variables, methods, blocks and nested classes.
  • Static variables declared as static is that is called static variable.

Example 1:

Output

Static Variable in Java
Next TopicData Types in Java