Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Variables in JAVA

    • 0
    • 5
    • 2
    • 0
    • 0
    • 0
    • 0
    • 0
    • 221
    Comment on it

    Variable is a name. Variable name reserved an area which is allocated in memory.
    In java each and every variable has some specific type, this specific type defines the size in variable's memory.
    One should declare variables before used.

    Eg. int a; // Here a is data type.
    a=50; // a is use and initialized as 50.

    There are three types of variables in java

    1. Local Variable

    2. Instance Variable

    3. Static Variable

    1. Local Variable Local variable are those variable which are declared inside method, constructors, or blocks. These variables are visible only within the declared method, constructor or block.

    2. Instance Variable A variable declared inside the class but outside the method, constructors, or blocks is called instance variable. such variables did not declared as static. These variables have a default values for example for numbers the default value is 0.

    3. Static Variable It is also known as Class Variable. It is declared with static keyword inside the class but outside method, constructor or a block. When program start static variable created and when program stop it destroyed. It is used to refer the common property of all objects and memory used only once in class area at the time of class loading i.e it saves memory.

    Eg.

    class Example
    
        {
            int a=10; // Instance Variable
            static int b=20; // Static Variable
            void method()
                {
                    int c=30; // Local Variable
                }
        }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: