1

System.out.println("init"); this statement is not within static block and not in any function or constructor, but still java doesn't give any error or warning and prints it before constructor sysout. why ?

public class A {

    public A()
    {
        System.out.println("A()");
    }
    public void print(int a) {

        System.out.println("integer");
    }
    {
        System.out.println("init");
    }
}

public class TestA {

    public static void main(String args[]) {

        A a = new A();

        a.print(new Integer(1));
    }
}

Output :

init
A()
integer
Kohei TAMURA
  • 4,970
  • 7
  • 25
  • 49
Ajinkya
  • 125
  • 7

0 Answers0