QUEUE USING STACK: PLACING OF " this "

In dequeue() and the front() functions or methods , Sir didn’t use " this " for referring the primary and secondary stack ?
I am a bit confused between when to use it and when not ?
Will it matter if I use it every time I write some code in my class ?
I am clear with the fact that " this " is used to refer to objects created in some other class.

HI @mananaroramail,
See there are two type of variables - Static and instance . Static variables are same for every object of a class and hence they do not need to be called with a object . But instance variable can store different values for different object hence for those variables it is necessary to provide the object which are you currently working on.
So we use this for instance variables to specify the object which we are working on . But in a case where we do not write this in front of a instance variable compiler will implicitly add this in front. But if there is a conflict where compiler does not know the difference in such case we have to provide it implicitly . For example consider this case
class Account{
int a;
int b;

public void setData(int a ,int b){
a = a;
b = b;
}
}
In this case setData does not know with a is referring to class variable and which is to a local hence in this we should have added a this like this .
class Account{
int a;
int b;

public void setData(int a ,int b){
this.a = a;
this.b = b;
}
}

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.