Variables in java (JNNC Technologies)


Variable is nothing but name of memory location in java.Each variable has the specific data type which defines size and layout of variable’s memory.
There are three kinds of variables in java.


Local variable:

A Variable which is declared inside a method can be termed as “Local Variable”. It is mandatory to initialize local variable otherwise Compiler will complain about it.

Instance variable:

A Variable which is declared at class level can be termed as “Instance variable”. It is not mandatory to initializeInstance variable.
All instance variable will be by default initialized by JVM.

Static variable:

A Variable which is declared as static is known as “Static variable”. Static variables are class level variables.
Let’s understand it with the help of simple program:
When you run above program, you will get below output:
Instance variable: 0
Static variable: 20
Method local variable: 10
That’s all about Variables in java.

Post a Comment

0 Comments

'; (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })();