This question was recently asked in an interview in which I attended.
public class MagicOutput {
public static void main(final String argv[]) {
System.out.println("Hello, World!");
}
}
I was asked to save both the main signature of the method (name, number and type of parameters, return type), and the implementation (body of the method),
and make this program to output to a standard console message "Magic Output !"
It took me about 2 minutes to answer. My solution was to put a static block there and output the required string.
static{
System.out.println("Magic Output !");
}
It works, but it prints both Magic Output !, andHello, World!
How can I make it output only the magic string?
source
share