Warning: CS dorkitude ahead...
Aug. 10th, 2004 12:50 pmThe next time you claim Java sucks, and someone tries to refute you, show them the below code. What does it do? What should it do? What do you wish it did? Where should the language designers stick it?
class Parent { static { System.out.println("Will the parent get a chance?"); } } public class Stupid extends Parent { static { System.out.println("Will this ever be printed?"); } public static void main (String[] args) { System.out.println("Perfectly normal operation"); Sly s = null; System.out.println("Another perfectly normal operation"); System.out.println("Yet another normal operation " + Sly.i); s = new Sly(); System.out.println("a final perfectly normal operation "); } } class Sly { static int i = 5; static { System.out.println("What about this? Will you print this?"); i = 1; } }( And the answer is.... )