Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
693 B
0
Indexable
Never
class StaticExample {
    static int count = 0; // static variable
    int id;
    static { // static block
        System.out.println("Static block executed");
    }
    StaticExample() {
        count++;
        id = count;
    }
    static void displayCount() { // static method
        System.out.println("Count: " + count);
    }
    void displayId() {
        System.out.println("Id: " + id);
    }
}
class StaticDemo {
    public static void main(String[] args) {
        StaticExample obj1 = new StaticExample();
        StaticExample obj2 = new StaticExample();
        obj1.displayId();
        obj2.displayId();
        StaticExample.displayCount();
    }
}