answersLogoWhite

0

An instance variable is typically associated with an object instance of the class whereas class variable is not associated with any object instance. Static variables are referred to as class variables while non-static regular variables are called instance variables. Simply put, you will have as many instances of the instance variable as there are object instances. i.e., if there are 10 instances of an object, you will have 10 instances of that instance variable as well. But, there will be only one instance of the static or class variable.

Instance variables are accessed as follows:

objname.variableName;

Class variables are accessed as follows:

ClassName.variableName;

User Avatar

Wiki User

11y ago

Still curious? Ask our experts.

Chat with our AI personalities

TaigaTaiga
Every great hero faces trials, and you—yes, YOU—are no exception!
Chat with Taiga
LaoLao
The path is yours to walk; I am only here to hold up a mirror.
Chat with Lao
MaxineMaxine
I respect you enough to keep it real.
Chat with Maxine

Add your answer:

Earn +20 pts
Q: What is difference between an instance variable and a class variable?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Math & Arithmetic

What is the difference between class variables and instance variables?

In the case of an instance variable, there is one copy for every instance (object). If you create 10 objects based on a class, there will be 10 copies of the variable. A class variable exists only once for the entire class - no matter how many objects you create - or even if you create no objects based on the class. In Java, such variables (class variables) are declared with the statickeyword.


What is difference between struct variable and class object?

structure variable can access the variable but class object can access the function also


What is Difference between local variable and data members or instance variable?

A data member belongs to an object of a class whereas local variable belongs to its current scope. A local variable is declared within the body of a function and can be used only from the point at which it is declared to the immediately following closing brace. A data member is declared in a class definition, but not in the body of any of the class member functions. Data members are accessible to all member function of the class.


What is refrence variable?

Reference variables in java is used to refer to an object. Its a way to access another variable or memory address with a variable and change the data inside the memory address. It gives direct access to the memory access. example:- Box b=new Box(); b is the reference variable of type Box. It can hold reference to any instance of class Box. new Box() creates an instance of class Box. So b is now pointing to an object of class Box. shreya..


What is the difference between class limits and class boundaries?

Let's say you're measuring a continuous variable such as height or speed. You collect tally charts with classes 30 - 39, 40 - 49, 50 - 59 etc. 49 would be an upper class limit, but 49.5 would be an upper class boundary, since a reading of 49.4 for example falls outside the class limits.