0

Hey just a question to prove me right or wrong. I am wondering what the 'this' in the following code refers to in terms of my applet.

mainThread = new Thread(this);

I believe that it refers to the run method which defines the thread. I was told I was wrong but given no answer so could someone enlighten me as to what it does?

Thanks a lot.

Lj

Edited by lj81

2
Contributors
3
Replies
4
Views
4 Years
Discussion Span
Last Post by JamesCherrill
0

In Java "this" is always the current object - the one whose context the current method is executing in. The Thread constructor takes an instance of Runnable as its parameter, so "this" must be an object whose class implements the Runnable interface (which consists of a single run method). When the thread is started it will call the run method for the "this" object.

0

Thanks very much. Thats what I said only not in so many words.:-)

0

Java programmers are very pedantic - they have to be. You said
"I am wondering what the 'this' in the following code refers to ... I believe that it refers to the run method".
So technically that's false, even if you did have the right idea.
Anyway, mark this thread solved?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.