java - what happens to static block when we create multiple objects? -


i have class has static members non-static members :

public class staticclassobjectcreations {     public static void dosomething() {         // todo implementations static     }      public void nonstaticmethod() {         // todo implementations non static     }      public static void main(string[] args) {          staticclassobjectcreations obj = new staticclassobjectcreations();         staticclassobjectcreations obj1 = new staticclassobjectcreations();       }  } 

as can see number of object creation not restricted , non-static methods can accessed of objects created new keyword.

the static methods or member variables available each instance , can accessed out creating objects also.

now question : how jvm maintains instances static block of code or in other words happens these static blocks when creating objects new keyword.

thanks.

static blocks/variable/methods belong class, not instances of class. initialized when class loaded. there won't effect these when create instance of class. if invoke static member instance, compiler replace instance class.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -