Write a program in java to demonstrate 2nd use of “this” keyword?

class This2

{

                int a,b;

                public This2()

                {

                                this(5,7);

                                System.out.println("Default");

                }

                public This2(int x)

                {

                                this(9,x);

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

                }

                public This2(int x,int y)

                {

                                a=x;

                                b=y;

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

                }

                public void display()

                {

                                System.out.println(a);

                                System.out.println(b);

                }

                public static void main(String arg[])

                {

                                This2 x1=new This2();

                                x1.display();

                                This2 x2=new This2(8);

                                x2.display();

                                This2 x3=new This2(4,6);

                                x3.display();

                }

}

2nd use of this Keyword.PNG

, , , , , ,

Leave a Reply