First of all, please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒
UseCodeTags ⇐ for more information. Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.
Secondly, make sure the code you post compiles successfully (unless you have of course a doubt about some compiler error then you need to post code which doesn't compile
). But in your code snippet class
Roo doesn't compile and I don't think that was intended.
Let's see how your code looks like when formatted and using code tags. And this code compiles successfully as well!
See how much easier the code is to read?
Aditya Desai wrote:I used to think that this.methodname() is used to call a method with methodname in the class which it is written.
That's not correct!
this is a reference to
the current object, the object whose method or constructor is being called. You can refer to any (instance) member (variables and methods) of the current object from within an instance method or a constructor by using
this. That means the instance members (variables and methods) defined in the current class, but also the inherited instance members (variables and methods) defined in the parent classes. In your code example the
doRooThings method is inherited from class
Roo and that's why you can invoke this method using
this in an instance method of class
Cloo.
Hope it helps!
Kind regards,
Roel