antony12 Posted January 14, 2023 Share Posted January 14, 2023 Hello and welcome! So, I recently finished a fairly lengthy programme on inheritance. I was instructed to provide a function toString() { [native code] } function in each class. The issue is that I have methods like getArea and getPerimeter in my subclasses. In my function toString() { [native code] } function for this class, I want function toString() { [native code] } to execute and, for example, output the region of the object that function toString() { [native code] } is invoked on. I just don't understand the syntax... I assumed it would be: "Area : " + this.getArea() However, it returns an error. So, in my function toString() { [native code] } class, how would I refer to this *unknown* object? Thank you very much! Link to comment Share on other sites More sharing options...
Totu487 Posted January 14, 2023 Share Posted January 14, 2023 The code you've written should work, provided that the object in which toString() is invoked on has a getArea() method (or if its superclass has a getArea() method). What error are you getting? antony12 1 Link to comment Share on other sites More sharing options...
Recommended Posts