Skip to main content

Posts

Showing posts with the label Java this keyword| this keyword in Java

Java this keyword

  this keyword in Java programming language is a reference variable that refers to the current object. this in Java is  a reference to the current object, whose method is being called upon. You can use this keyword to avoid naming conflicts in the method/constructor of your object. What are the usages of this keyword in Java Programming Language . 1) this can be used to refer the current class instance variable. 2) this can be used to invoke current class method. 3) this() method ca be used to invoke current class constructor. 4) this can be passed as an arguments in the method call. 5) this can be passed as an arguments in the constructor call. 6) this can be used to return the current instance from the method. Lets see an example to understand how actually this keyword works.. class student { int roll_no;  //  variable declaration  String Student_name; // variable declaration float fees; //variable declaration student(int roll_no, String Student_name, float fees) // parameter