When Are The Non Static Variables Loaded into The Memory

They are loaded just before the constructor is called.

In Java, non-static variables (also known as instance variables) are loaded into memory when an object is instantiated or created. These variables are associated with the instance of the class, and memory is allocated for them when you create an object of that class using the new keyword.

For example:

java
public class MyClass {
// Non-static variable
int myVariable;
public static void main(String[] args) {
// Creating an object of MyClass
MyClass obj = new MyClass();

// Now, memory is allocated for the non-static variable “myVariable”
// and it is associated with the instance (object) “obj”
}
}

In this example, when you create an object obj of the class MyClass, memory is allocated for the non-static variable myVariable, and it is associated with the instance obj. If you create multiple objects of the same class, each object will have its own set of non-static variables.