If your class doesn’t have a PSVM (main method), is there a way to print something on console?
Yes, use Static blocks.
- Static blocks is mostly used for changing the default values of static variables.
- A static block gets executed when the class is loaded into memory
- A class can have multiple static blocks which will be executed in the order in which they are written.