java - Change output without modifying code -
This question was recently asked in an interview that I participated. Public class MagicOutput {public static zero main (last string argv []) {System.out.println ("Hello, World!"); }}
The main signature of the method (name, number and parameter type, return type) and implementation (body of method),
The program was told the standard console message I took about 2 minutes to answer. My solution was to put a static block there and essential string output. But this works, it prints both How do I output it to only Magic String? or fun (depending on string implementation - works with openjdk 8): "Magic Output!" To output to
Fixed {System.out.println ("Magic Output!"); }
magic outputs! and
Hello, world!
static {System.out.println ("magic output!"); System.exit (0); }
static {System.out.println (" Magic output! "); Try {field f = string.clash.gateclined field ("value"); f.setAccessible (true); f.set ("hello, world!", new four [0]); f.set (System.lineSeparator (), new four [0]); } Hold (ignoring the exception) {}}
Comments
Post a Comment