this is a java keyword used to store the reference identifier of the current object.
So far, this() is the default constructor call in the java program .
Code snippet for this() :
class ThisTest{ ThisTest(){ System.out.println("this is the default constructor of your class"); } ThisTest(int val){ this(); System.out.println("this is the parameterized constructor of your class and the passed value is "+val); } public static void main(String...args){ ThisTest tt=new ThisTest(10); } }
In the above code, you created an object of your class using a parameterized constructor, but this() must be the first in your constructor to call any other constructor.
You can also change the above code to:
ThisTest(){ this(10); //above code } ThisTest(int val){ //above code } public static void main(string...args){ ThisTest tt=new ThisTest(); }
source share