Sitemap
Rashidautturkar

Rashidautturkar

Variables in java

1 min readJul 9, 2020

--

A variable is a name which is associated with a value that can be changed. For example: int i=15; here variable name is i which is associated with value 15, int is a data type that represents that this variable can hold integer values.

How to Declare a variable in Java To declare a variable follow this syntax:

data_type variable_name = value;

here value is optional because in java, you can declare the variable first and then later assign the value to it.

Types of Variables in Java

Get Rashidautturkar’s stories in your inbox

Join Medium for free to get updates from this writer.

There are three types of variables in Java.
1) Local variable 2) Static (or class) variable 3) Instance variable.

Static variable

Static variables are also known as class variable because they are associated with the class and common for all the instances of class.

Instance variable

Each instance(objects) of class has its own copy of instance variable. Unlike static variable, instance variables have their own separate copy of instance variable.

Local variable

These variables are declared inside method of the class. Their scope is limited to the method which means that You can’t change their values and access them outside of the method.

--

--