Skip to content
Advertisement

Tag: this

Why can I not use “super” variable from a static context, even though “super” refers to the parent class and NOT a class instance, unlike “this”?

I’m talking java language. Variable “this”, when used inside a class, refers to the current instance of that class, which means you cannot use “this” inside a static method. But “super”, when used inside a class, refers to the superclass of that class, not an instance of the superclass, which should mean that you can use “super” inside a static

C++ equivalent to Java this

In Java you can refer to the current object by doing: this.x = x. How do you do this in C++? Assume that each of these code examples are part of a class called Shape. Java: C++: Answer Same word: this Only difference is it is a pointer, so you need to use the -> operator:

Advertisement