Instance(Object) Variable

Published: (January 30, 2026 at 06:54 AM EST)
1 min read
Source: Dev.to

Source: Dev.to

What is an Instance Variable in Java?

  • An instance variable is a variable that belongs to an object (instance) of a class.
  • Every object gets its own copy of this variable.
  • Declared inside a class but outside methods.
  • Its value can differ for each object.

Where are instance variables stored in memory?

  • Stored in heap memory.
  • Memory for these variables is allocated when a new object is created.
  • They exist as long as the object exists.

Do instance variables have default values?

If not explicitly assigned, instance variables receive default values:

  • short = 0
  • byte = 0
  • int = 0
  • long = 0
  • float = 0.0
  • double = 0.0
  • char = '\u0000'
  • boolean = false
  • String = null

How to access this variable?

Access instance variables through an object using the dot (.) operator:

ObjectName.variableName

Where is it declared?

Inside the class but outside any methods.

What is another name for object variables?

They are also called instance variables.

Back to Blog

Related posts

Read more »

Day-4 Data Types

Data types Data types are the kinds of information stored in a variable e.g., numbers, characters, true/false, etc.. There are two categories of data types: -...

Day-3 details of Class and Object

Class - Class is a Java keyword - Class is a template - Class is a logical entity - First letter of the class name should be capital CamelCase, e.g., SalaryAcc...