In an interview I have asked this question:Without using static and main how could we print message on console?Is it possible?
You could define a custom class loader that prints your message :
public class MyClassLoader extends ClassLoader {
public MyClassLoader(ClassLoader other) {
super(other);
System.out.println("Hi there");
System.exit(0);
}
}
Then run the java command :
java -Djava.system.class.loader=MyClassLoader
(don't need to add a class as parameter)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With