this keyword can be used to return current class instance
Java Programming Language Class, Object and Methods in java (Article) Class, Object and Methods in java (Program)
3335Program:
//Example of this keyword that you return as a statement from the method class ClassMe{ ClassMe getClassMe(){ return this; } void display(){ System.out.println("Don't confuse"); } } class MainClass{ public static void main(String args[]){ new ClassMe().getClassMe().display(); } } /* this keyword can be used to return current class instance: We can return this keyword as an statement from the method. In such case, return type of the method must be the class type (non-primitive). */
Output:
Don't confuse Press any key to continue . . .
This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.