During execution, any number of objects can be created for the same .class file, but the context of the class can be created only once for a given class file

As long as the address of the object (instant of class) is persistent in RAM, the object is persistent in RAM. As long as the main () method is under execute

Difference between Context of a class and Instance of a class

The context of the class exists in the RAM once control encounters closing} of main (), the context of the class is deleted from the RAM.

Garbage collection of objects will not have any effect on the context of the class, but deletion of the context of the class from the RAM deletes everything

related to that .class file from the RAM.

The context of a class will be defined before creating an object of that class. But the object of the class would be created only after the context of the class is created.

 

Example:

Class sdemo1

{

Int I;

Static int j;

Static void function1 ()

{

System . out . println (j);

J=j+1;

S demo1 s1 = new sdemo1 ();

S1 .i=15;

System. out. println (s1 .i);

}

Public static void main (string args [ ])

{

Function1 ();

Function 1();

S demo1 s1 = new sdemo1 ();

S1.i =150;

System. out. println (s1 .i);

}

}

 

Explanation:

Since function1 () is a static function, it will not be deleted from the RAM as soon as once the control comes out from the function. It will be deleted only when the control completes the execution of the main () method.

So we can call this function as many numbers of times as required. If the function1 () is not a static function, then to get access to the function, we need to create an object of the class. Now we can call the function through the object.

 

Difference between Context of a Class and Instance of a class Homework Help