this reference-this keyword in java programming is used to refer the current class object. this keyword is used when we want to call methods without creating object. this reference stores in the memory when an object of the current class is instantiated. We can say "this" is a special keyword in java programming which is used to refer current class object or instance of any class. By using this keyword we can call methods of current class as well as constructor. Let us see use of this reference in java and its interesting example.
- this is the keyword of java.
- this reference holds the address of current class's object.
- this reference can not be used inside any static context.
- this reference can be used inside any non-static context.
- this reference refers to the current class object.
- this reference stores in the memory how many times object of the class is instantiated.
here, this keyword is holding the reference of the current class object so it can also call the any method of the same class. however we can also call the methods without this reference such as-
this reference is very useful in some cases like-
public static void main(String args)
This1 d1=new This1();
This1 d2=new This1();
This1 d3=new This1();
It completes the discussion of this reference.we will discuss about this-call later. For more study about this reference please follow these links-