Junior — Middle
Where are static functions and data located in object-oriented programming?
sobes.tech AI
Answer from AI
In object-oriented programming, static functions (methods) and static data (fields) belong to the class itself, not to individual objects. In Java, they are declared using the static keyword and are stored in a memory area associated with the class, not with instances.
Example:
class Example {
static int staticCounter = 0; // static field
static void staticMethod() { // static method
System.out.println("Static method called");
}
}
Static members are accessible without creating an object of the class.