Code:
class VI{
{
System.out.println("Non static block called");
}
VI()
{
System.out.println("Constructor block called");
}
public static void main(String a[])
{
VI v=new VI();
}
}
The code snippet comprises class again it comprised of non static block along with constructor.
So, when obejct of class is created the non static block will be called and after that constructor is called.
So, can we say non static block as constructor of class?
Terminal commands:
vivek@ubuntu:~/Prime_project/python-SLR-parser$ javac VI.java
vivek@ubuntu:~/Prime_project/python-SLR-parser$ java VI
Non static block called
Constructor block called
vivek@ubuntu:~/Prime_project/python-SLR-parser$