Non-Static Members and their Execution Control Flow

Java 10 min min read Updated: Mar 31, 2026 Intermediate
Non-Static Members and their Execution Control Flow
Intermediate Topic 17 of 25

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.

Key Concept: Non-static members belong to objects, not the class. They are created during object creation, and their execution flow starts only when an object is instantiated.

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

java class Student { String name; int age; }

Here, name and age are instance variables.

Using Instance Variables

java public class Main { public static void main(String[] args) { Student s1 = new Student(); s1.name = "Amit"; s1.age = 20; Student s2 = new Student(); s2.name = "Riya"; s2.age = 22; System.out.println(s1.name + " - " + s1.age); System.out.println(s2.name + " - " + s2.age); } }

Output

text Amit - 20 Riya - 22

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

java class Demo { int x; boolean flag; String name; } public class Main { public static void main(String[] args) { Demo d = new Demo(); System.out.println(d.x); System.out.println(d.flag); System.out.println(d.name); } }

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

java class Student { String name; void display() { System.out.println("Name: " + name); } }

This method must be called using an object.

java public class Main { public static void main(String[] args) { Student s = new Student(); s.name = "Amit"; s.display(); } }

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

java class Demo { { System.out.println("Instance block executed"); } Demo() { System.out.println("Constructor executed"); } } public class Main { public static void main(String[] args) { Demo d1 = new Demo(); Demo d2 = new Demo(); } }

Output

text Instance block executed Constructor executed Instance block executed Constructor executed

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.

java class Student { Student() { System.out.println("Object initialized"); } }

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:

  1. Memory is allocated for the object in heap
  2. Instance variables receive default values
  3. Instance variable initializers execute in source code order
  4. Instance blocks execute in source code order
  5. Constructor executes
Remember: During object creation, the flow is: default values → instance variable initialization → instance blocks → constructor.

Example of Non-Static Execution Flow

java class Demo { int a = 10; { System.out.println("Instance block 1"); System.out.println("a = " + a); } int b = 20; { System.out.println("Instance block 2"); System.out.println("b = " + b); } Demo() { System.out.println("Constructor"); } } public class Main { public static void main(String[] args) { new Demo(); } }

Expected Output

text Instance block 1 a = 10 Instance block 2 b = 20 Constructor

Explanation

  • Object memory is allocated
  • a is initialized first
  • First instance block runs
  • b is 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

java class Demo { int x; { System.out.println("Before assignment: " + x); x = 50; System.out.println("After assignment: " + x); } Demo() { } } public class Main { public static void main(String[] args) { new Demo(); } }

Output

text Before assignment: 0 After assignment: 50

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.

java class Demo { { System.out.println("Instance block 1"); } { System.out.println("Instance block 2"); } Demo() { System.out.println("Constructor"); } } public class Main { public static void main(String[] args) { new Demo(); } }

Instance Methods and Execution

Instance methods do not run automatically during object creation. They execute only when they are invoked using an object.

Example

java class Demo { void show() { System.out.println("Instance method executed"); } } public class Main { public static void main(String[] args) { Demo d = new Demo(); d.show(); } }

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.

java class Demo { static int x = 100; void display() { System.out.println(x); } }

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.

java class Student { String name = "Amit"; void showName() { System.out.println(name); } void display() { showName(); } }

Real-World Example of Non-Static Members

Consider a bank account system where each account must store unique account information.

java class BankAccount { String accountHolder; double balance; { System.out.println("Preparing account object"); } BankAccount(String accountHolder, double balance) { this.accountHolder = accountHolder; this.balance = balance; } void showDetails() { System.out.println(accountHolder + " - " + balance); } } public class Main { public static void main(String[] args) { BankAccount a1 = new BankAccount("Amit", 5000); BankAccount a2 = new BankAccount("Riya", 8000); a1.showDetails(); a2.showDetails(); } }

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.

Quick Summary: Non-static members belong to objects, require object creation for access, and follow the execution order: default values → instance variable initialization → instance blocks → constructor.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators