Database Related

Difference Between A Class Variable And An Instance Variable

Instance variables have distinct values for every instance of a class. Class variables keep up a solitary shared quality for all instances of the class, regardless of the possibility that no instance object of that class exists.

You would utilize the static keyword to change an instance variable into a class variable.

In general,

Instance variables:

These variables have a place with the instance of a class, subsequently an object. Furthermore, every instance of that class (object) has it’s own duplicate of that variable. Changes made to the variable don’t reflect in different instances of that class.

public class Product {

public int Barcode;



Class variables:

These are otherwise called static member variables and there’s one and only duplicate of that variable that is imparted to all instances of that class. In the event that progressions are made to that variable, every single other instance will see the impact of the progressions.

public class Product {

public static int Barcode;


Leave a Reply