#What does this in this case mean?
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
for the int ownArea i mean
What i have understood is i am currently making a method so when i call this method i will use the object and here this reference to the caller objects variable right?
no, this refers to the current instances variables.
Say for that largerThan you passed in (int squares, int rooms) where they were respectively 10, 9.
And you created the instance with 20, 18.
this.rooms would be 20, rooms would be 10.
largerThan is taking object instance not a primitive data type
i think
@iron sleet
Look at my example with the signature change.
No.
And my example had different parameters to make it clearer.
With this. you refer to the variables of the current object instance.
i get what you mean but your example is not making sense to me
class Foo {
int x;
Foo (int x) {
this.x = x;
}
void printFoo(int x){ // this is 10
System.out.println(this.x); // prints 5
System.out.println(x); // prints 10
}
public static void main(String[] args) {
new Foo(5).printFoo(10);
}
}
that code wont compile