Static variable in java class

I want to ask if the static variable in the class will add additional memory to the initialized class.

Let's say I have a class like 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 I create the Sample class several times, initializing it and adding to the array of the Sample class, does the static variable add extra memory to the class or will it only get one memory location when it is static?

+4
source share
1 answer

static , . static, . .

static , .

+6

Source: https://habr.com/ru/post/1623314/


All Articles