Aug. 10th, 2004

pmb: (Default)
The 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.... )

Profile

pmb: (Default)
pmb

October 2009

S M T W T F S
    1 23
45678910
11121314151617
18192021222324
25262728293031

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Sep. 13th, 2025 08:36 am
Powered by Dreamwidth Studios