This is some information on the Java 6 certification that I prepare. This information is not very well structured and it is most of the time an answer to the questions that come when I read the SCJP 6 book (Bates and Sierra). *** AS OF 5 OF MARCH 2010, I AM SCJP 6.0 ***

Monday, March 1, 2010

34 - What is printed ?

To relax you a little please make the following exercice and guess what is going to be printed ?


package ex1;

public class Main {

    String hello = "hello";

    {
        System.out.println(this.hello);
        System.out.println("block1");
    }

    public static void main(String[] args) {

        new Main().fool();

    }

    Main() {
        System.out.println("Main");
    }

    void fool() {
        System.out.println("fool");
    }

    {
        System.out.println("block2");
    }
}

==========
































run:
hello
block1
block2
Main
fool

No comments:

Post a Comment

Followers