Write a program in java to demonstrate anonymous block?

class Anonymous

{

                int x,y;

                String s1;

                //            Anonymous Block

                {

                                System.out.println("Hi I am Anonymous");

                }

                public Anonymous()

                {

                                System.out.println("Hello Default");

                }

                public Anonymous(int a)

                {

                                x=a;

                                System.out.println("One Parameterize");

                }

                public Anonymous(String s2)

                {

                                s1=s2;

                                System.out.println("One Parameterize String");

                }

                public static void main(String arg[])

                {

                                new Anonymous();

                                new Anonymous(7);

                                new Anonymous("India");

                }

}

Anonymous Block.PNG

, , , , ,

Leave a Reply