What are the Active Uses of a Class?
There are six active uses of classes that JVM should go through the initialization phase before comes to those cases.
- Process ‘new’ Keyword
For an example, create a new object of Employee, from the Company class. [Employee emp1= new Employee( ); ]
- Invoke a Static Method
For an example, Employee class has a static method called verifyEmployee( ).
So, without creating an object, you just can invoke that method from Company class. [ Employee.verifyEmployee( )]
- Assign Value for a Static Field
For an example, Employee class has a static variable called employeeCode.
So, without creating an object, you just can call that field from Company class. [ Employee.employeeCode = ‘‘executive” ]
But if that static field is final, if you access it, it will not take as an active use.
- Execute the Initial Class
If JVM is executing the class which has the main method, it is an active use.
- Invoke a Reflection Method
For an example, if you use, getInstance( ) method from Reflection API, it considers as an active use.
- Invoke Instance Subclass
For example, if you execute Manager class which is subclass of the Employee (which consist with static fields, static methods).