What will be output of following java program? (Static Interview Question)

class A

{

                static

                {

                                System.out.println("A is Loaded");

                }

                public A()

                {

                                System.out.println("A is instantiated");

                }

}

class B

{

                static int b;

                static

                {

                                b=7;

                                System.out.println("B is Loaded");

                }

}

class C

{

                static

                {

                                System.out.println("C is Loaded");

                }

                public static void display()

                {

                                System.out.println("C is Loaded By Static Method");

                }

}

class StaticTest

{

                static

                {

                                System.out.println("StaticTest is Loaded");

                }

                public static void main(String arg[])

                {

                                System.out.println("Main() is Invoked");

                                A x=new A();

                                System.out.println("Class B is Loaded by Static Data Member");

                                System.out.println("Value is "+B.b);

                                System.out.println("Class is Called");

                                C.display();

                                System.out.println("A is Instantiated Again");

                                A y=new A();

                }

}

Static Block & Constructor & Class.PNG

, , , , , , , , , ,

Leave a Reply