Static variable in class java -


i want ask if static variable in class add memory the initialized class.

lets have class this:

public class sample{      public static string name[] = {"1", "2", "3", "4"};      private int id;      private string uuid;     private string name;      public void setuuidstring() {         uuid uuid = uuid.randomuuid();         this.uuid = uuid.tostring();     }      public void setname(string name) {         this.name = name;     }      public void setcustomuuid(string uuid) {         this.uuid = uuid;     }      public void setid(int id) {         this.id = id;     }      public int getid() {         return id;     }      public string getuuid() {         return uuid;     }      public string getname() {         return name;     } } 

and create sample class multiple times initializing , adding array of sample class static variable adds memory the class or only 1 memory location when static?

since static variables initialized @ start of programs execution, memory set aside variable. since variable static belongs class not instances of class. every instance create will not use memory.

with static variables single instance of variable shared throughout instances of class, although not need instance of class access variable.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -