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 »

JDK

What is JDK? JDK is a complete software package used to develop Java applications. It contains tools to write, compile, debug, and run Java programs. When is J...

Operators

What are Operators in Java? Operators are symbols used to perform operations on variables and values. Types of Operators in Java - Arithmetic Operators - Assig...