Skip to main content

Use of this keyword - Please explain the complex code here

Please note these forums are being decommissioned and use the new and improved forums at
1 reply [Last post]
Joined: 2013-06-07

class B{
A obj;
B(A obj){
void display(){
System.out.println(;//using data member of A class

class A{
int data=10;
B b=new B(this);
public static void main(String args[]){
A a=new A();


Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2014-07-06

Usage of this keyword:

1. this keyword can be used to refer current class instance variable.

2. this() can be used to invoke current class constructor.

3. this keyword can be used to invoke current class method (implicitly)

4. this can be passed as an argument in the method call.

5. this can be passed as argument in the constructor call.

6. this keyword can also be used to return the current class instance.

read more in detail:-