Sobes.tech
Junior — Middle

Is a constant part of the class as a whole or of a specific instance of it?

sobes.tech AI

Answer from AI

In Java, a constant declared in a class with the modifiers static final is part of the class as a whole, not of a specific instance. This means that such a constant is stored in a single instance and is accessible without creating an object of the class.

Example:

public class MyClass {
    public static final int CONST_VALUE = 10;
}

// Accessing the constant
int value = MyClass.CONST_VALUE;

If the constant is declared without static, then it will belong to a specific instance of the class, but usually constants are made static.

Is a constant part of the class as a whole or of a… - sobes.tech