Scope of Variables in Java

Java variables are mainly classified into three kinds :

  • Local Variables
  • Instance Variables
  • Class Variables

    1. Local Variables : Variables declared and which is used inside methods that are called Local variables. Local variables can also be declared inside program blocks that are defined between an opening brace { and a closing brace }. These variables are visible to the program only from the beginning of its program block to the end of the program block.

    2. Instance Variables : Instance variables are declared inside a class, it is created when the objects are instantiated and therefore it is associated with the objects.

    3. Class Variables : Class variables are also declared inside a class. Class variables are global to a class and belong to the entire set of objects that class creates. Only one memory location is created for each class variable.

    Recommended Posts:

        1. Features of Java
        2. Java Program Structure
        3. Command Line Arguments in Java
        4. Difference between java and c++
        5. Java Data Types
        6. Scope of Variables in Java
        7. Operators in Java
        8. Looping Statement in Java
        9. Objects and Classes in Java
        10. Constructors in Java
        11. Method Overloading in Java with Program