uses of this keyword in java || 3 uses you must know || part 5

preview_player
Показать описание
Let's learn few most important uses of this keyword.This tutorial covers
1.How to use this, to return current class instance
2.How to use this in return statement of a method
3.How to use this inside a method argument
4.How to use this inside a constructor argument

-- For other uses of this keyword follow my below tutorials:

this/this() real time use :

follow us on facebook:
Рекомендации по теме
Комментарии
Автор

Current class instance means current class object! Thank you so much. You are an amazing tutor. I really liked your video.

thestarinthesky_
Автор

Hi Bro..., Your tutorial is good!

As you have told below will return the same reference but its return the different reference in both cases because in method m2() its creating a new object of class A. Please clarify more if possible for you.

A m1(){

return this;
}

or

A m2(){
A s=new A();
return s;
}

public static void main(String[] args){
A a =new A();
}

if we return this keyword then the calling object reference is same as this.... But in case of m2() its different. But according to you both should be same.

Bro please correct me if I am wrong.

Keep it up to make more good videos....

anshul
Автор

What does the "this" refer to in the m2 method when you called m1(this);


Thanks a lot

teoweide
Автор

Your board is reflecting light in it.So, please make sure that.

surajchennoju
Автор

Watched it twice. Let me watch this 5 more times .... I'm trying to understand

KaisarAnvar
Автор

Nice explanation. Just one suggestion. Be proud of Indian English accent and use the same. When we Indians try to use American/European accent it doesn't look natural . :)

Also NO background music please :)

kshitijshrivastava
Автор

public class A {

A m1 ()
{
A a1 = new A();
System.out.println(this + " " + a1);
return a1;

}

public static void main(String[] args) {
A a1 = new A();


a1.m1();



}

}


You said that they are the same while they are not ! This refers to current class instance while "A a1 = new A();
" creates new object with assigning new memory address

thestarinthesky_