Variables in Java- vishmy1.blogspot.com

Variables in Java :-

In Programming a Variable is a Location capable of storing Temporary Data within a program. This data can be Modified, stored or display whenever needed. the size of the variable depends upon the range over which the variable is allow.

A Variable Definition tells the compiler where and how much storage to create for the variable.

A Variable Definition specifies a datatype and contains a list of one or more of that type.


Syntax :-  datatype  variable_name

Types Of  Variable :-



There are four type of Variables :-

  • Local Variable.
  • Instance Variable.
  • Static Variable.
  • Parameter Variable.

1)- Local Variable :-

A Variable that is declared inside the method is called Local Variable.

2)- Instance Variable or Global Variable :-

A Variable that is declare inside the class but outside the method is called Instance Variable or Global Variable

3)- Static Variable :- 

The Variable that is declare as static is called Static Variable.

4)- Parameter Variable :-

Parameter or Arguments are the Variables in Method Declaration.

Ex :-

class test
{
     int a=5; //instance(global) Variable.
     static int b=10; //static variable.
     public void accept(string name) //string name is parameter variable
    { 
int age=18;//Local Variable
        System.out.println("Your Name is:"+s );
        System.out.println("Your Age is:"+age );
     }

    public static void main(String args[])
    {
test t1=new test();
t1.accept("vishal");
        System.out.println("a="+a+ "b="+b);
    }
}



       





Post a Comment

1 Comments

  1. Nice article keep this great work up. There is good java variable tutorials Click Here

    ReplyDelete