Tuesday, 1 May 2018


instance control flow:----------------
whenever we are executing a java class first static control flow will be executed
in the static control flow if we are creating an object the following sequence of events
is executed as the part of instance control flow.

1. identification of instance members from top to bottom
2. execution of  instance variable assignments and instance block from top to bottom.
3.execution of constructor

public class Test {
           
            int i=10;
           
            {
                        m1();
                        System.out.println("ist instance block");
                       
            }

           
            Test()
            {
                        System.out.println("constructor");
            }
           
           
            public static void main(String[] args) {
                        Test t=new Test();
                        System.out.println("main");
            }

            public void m1()
            {
                        System.out.println(j);
            }
           
            {
                        System.out.println("second instance block");
            }
           
             int j=20;
           
     }

o/p:-------------
0
ist instance block
second instance block
constructor
main

No comments:

Post a Comment