Untitled
unknown
plain_text
2 years ago
693 B
2
Indexable
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(); } }
Editor is loading...