Junior — Middle
Can you explain what is meant by a static field in object-oriented programming?
sobes.tech AI
Answer from AI
A static field in object-oriented programming is a variable that belongs to the class itself rather than to any specific instance of the class. This means that all instances of the class share the same value of this field.
For example, in Java:
public class Counter {
public static int count = 0;
public Counter() {
count++;
}
}
Here, the count field will increase each time a new Counter object is created, and its value will be shared among all instances.