Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
677 B
1
Indexable
Never
public class StaticDemo {
    // Static variable
    static int count = 0;

    // Static block
    static {
        System.out.println("Static block executed");
        count = 5;
    }

    // Static method
    static void incrementCount() {
        count++;
    }

    public static void main(String[] args) {
        System.out.println("Initial count: " + count);
        
        incrementCount();
        System.out.println("Count after increment: " + count);
        
        StaticDemo obj1 = new StaticDemo();
        StaticDemo obj2 = new StaticDemo();
        
        System.out.println("Count after creating objects: " + count);
    }
}