Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Class Loading Doubt..  RSS feed

 
Clarence J M Tauro
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let us consider the following code with two different classes:



When I just create a reference in "main", will the Employee class be LOADED?
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you create a reference to an Employee object, yes, the Employee class will be loaded. But the code you posted does not create a reference. It simply declares a variable of Employee type, and that doesn't cause the Employee class to be loaded.

Here's some code which creates a reference:
 
Clarence J M Tauro
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul;

Now, which means when I just do



the class does not get loaded, and static initilizer/block does not get called right. I also verified the same.

Now can I have the static block of Employee class executed without creating the instance of the class or accessing some static method or variable of Employee class? I mean to say, how do we load the class directly?
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Clarence J M Tauro
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!