DEFINITION 10: INSTANCE VARIABLE - PRATMG/2143-OOP-Tamang GitHub Wiki

Instance variables are non-static variables that are declared outside of any method, constructor, or block in a class.

  • Since instance variables are declared in a class, they are created when a class object is created and destroyed when the object is destroyed.
  • Instance variables can be accessed using access specifiers. If no access specifier is specified, the default access specifier will be used.
  • It is not necessary to initialize the instance variable.
  • Instance Variables can only be accessed by creating objects.

INSTANCE-var

class Example
{
    static int a; // static variable
    int b;        // instance variable
}