[Solved] Is the ‘this’ pointer only hidden in C++ or in java too? [closed]


Hidden? It’s not hidden. What does that even mean?

I do remember that you have to explicitly use it in Java

Only in some circumstances. A variable called name could be known inside the class and also be the name of a parameter in a method. Example:

class Test {
    String name;

    public void test(String name) {
        name = name; // What happens?
    }
}

Both times name is mentioned it refers to the parameter. The class field is unchanged. You have to tell the compiler that you want this.name if you want the class field.

In other circumstances, when there are no collision in names, the this. part is implicit. Example:

class Test {
    String tutorName;

    public void test(String name) {
        tutorName = name; // What happens?
    }
}

The class field is changed even though you didn’t use the this keyword.

4

solved Is the ‘this’ pointer only hidden in C++ or in java too? [closed]