Static Variables in Java


Static variables are shared among all instances of a class.

Source Code

class MyClass {
    static int staticVariable = 10; // Belongs to the class, not a specific instance
    int instanceVariable = 20; // Each object instance has its own copy
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments