Non-Static Members and Their Execution Control Flow
In Java, non-static members are members that belong to an object rather than to the class itself. These members are also called instance members because each object gets its own copy of them. Understanding non-static members is very important because most object-oriented programming in Java revolves around objects and their instance data.
Along with non-static members, interview discussions often include the execution control flow of instance variables, instance blocks, constructors, and instance methods. This topic helps you understand what happens when an object is created and how Java initializes object-specific data.
What are Non-Static Members?
Non-static members are the members of a class that do not use the static keyword. They are associated with objects and require object creation for access.
Non-static members include:
- instance variables
- instance methods
- instance blocks
- constructors
These members cannot be used directly with the class name because they belong to individual objects.
Why Non-Static Members are Important
Non-static members are necessary when each object needs its own separate data and behavior.
- each student has a separate name and age
- each bank account has a separate balance
- each employee has a separate ID and salary
If such data were static, all objects would share the same values, which would be incorrect in most real-world cases.
Instance Variable
An instance variable is a variable declared inside a class but outside methods, constructors, and blocks, without the static keyword.
Each object gets its own separate copy of instance variables.
Example
Here, name and age are instance variables.
Using Instance Variables
Output
This shows that each object has separate values for the same instance variables.
Default Values of Instance Variables
If instance variables are not explicitly initialized, Java gives them default values.
| Type | Default Value |
|---|---|
int |
0 |
double |
0.0 |
boolean |
false |
char |
'\u0000' |
| Reference types | null |
Example
Instance Method
An instance method is a method that belongs to an object and does not use the static keyword.
Instance methods can directly access:
- instance variables
- instance methods
- static variables
- static methods
Example
This method must be called using an object.
Instance Block
An instance block is a block written directly inside a class without the static keyword and outside methods and constructors.
It executes every time an object is created, before the constructor executes.
Example
Output
This confirms that instance blocks are executed for each object creation.
Constructor as a Non-Static Member
A constructor is also part of the object initialization flow. It executes when a new object is created.
Constructors are not inherited and are closely connected with object creation.
Execution Control Flow of Non-Static Members
The execution flow of non-static members starts when an object is created using the new keyword.
The general order is:
- Memory is allocated for the object in heap
- Instance variables receive default values
- Instance variable initializers execute in source code order
- Instance blocks execute in source code order
- Constructor executes
Example of Non-Static Execution Flow
Expected Output
Explanation
- Object memory is allocated
ais initialized first- First instance block runs
bis initialized next- Second instance block runs
- Finally, constructor runs
Instance Variables First Get Default Values
Before explicit assignments, instance variables first get their default values.
Example
Output
This shows that the instance variable first received its default value 0.
Multiple Instance Blocks
A class can have multiple instance blocks, and they execute in the order they appear in the source code.
Instance Methods and Execution
Instance methods do not run automatically during object creation. They execute only when they are invoked using an object.
Example
Here, the method show() executes only after explicit invocation.
Can Non-Static Members Access Static Members?
Yes. Instance methods and constructors can directly access static members because static members belong to the class and are already available.
Can Non-Static Members Access Other Non-Static Members?
Yes. Since they all belong to the same object, instance methods and constructors can directly access instance variables and other instance methods.
Real-World Example of Non-Static Members
Consider a bank account system where each account must store unique account information.
Here:
- each object has different values
- instance block runs for each object
- constructor initializes each object separately
- instance method displays object-specific data
Non-Static Members vs Static Members
| Point | Non-Static Members | Static Members |
|---|---|---|
| Belongs to | Object | Class |
| Object required? | Yes | No |
| Memory allocation | At object creation | At class loading |
| Shared? | No | Yes |
| Execution begins | During object creation | During class loading |
Common Mistakes
- Thinking instance variables are shared like static variables
- Assuming instance methods can run without an object
- Confusing instance block execution with method invocation
- Forgetting the execution order of instance variables, blocks, and constructors
- Using object-specific data in a static design when separate copies are needed
Best Practices
- Use non-static members for object-specific data and behavior
- Use constructors to initialize objects clearly
- Use instance blocks only when common constructor logic must be shared
- Keep object state meaningful and well-encapsulated
- Understand execution order to avoid initialization bugs
Interview-Oriented Points
- Non-static members are also called instance members
- They belong to objects, not the class
- Each object gets its own copy of instance variables
- Instance methods require object creation
- Execution flow of non-static members starts with object creation
- Order is default values → instance variable initialization → instance blocks → constructor
- Instance members can directly access both instance and static members
Conclusion
Non-static members are the heart of object-oriented programming in Java because they represent object-specific data and behavior. They allow every object to maintain its own independent state and behavior.
Understanding the execution control flow of non-static members is essential for mastering object creation, initialization, and method execution in Java. This knowledge is highly important both in interviews and in real application development.

