Skip to main content

Posts

Showing posts with the label non static variable in java

Types of Variables

Types of Variables:- There are total three types of variables in java, according to the place where variables declared. Variables may be primitive types or secondary type.  1)   Instance variable or non static instance variable.  2)   Static variable.   3)  Local variable. Instance variable: -   A variable which is declared inside class but outside methods, called instance variable. Instance variables are directly related to objects, each object of class contains separate copy of instance variables of class. All instance variables occupied memory inside object and initialize with default value when object created. Object always created in heap area of jvm at run time not at compile time. Example:- class Student { String name; String lastName; int rollNo; String course; float percentage; } In the above class all variables are instance variable. Static variable:- A variable which is declared inside cla...