I am trying to write an abstract class. In that class I have a method which is supposed to access the actual object for which the method is called. "this" however will only return the "part of the object" that I write myself (the abstract one).
this
will return a reference to "the whole" object, not "a part". To proof this, if you cast this reference to a class that is lower in the hierarchy, you can access any property or method of this class using the instance referenced by this.
However, casting the instance referenced by this
, would not be a good design practice. Speaking in general terms, you should write a foo method in MyClass with the general behaviour, and override it with the particular behaviour of each classs. If you want to use the foo method of the parent class, you can invoke it using super
.