Leandro Coutinho wrote:Just for convenience?
Leandro Coutinho wrote:
I would like to know:
- What does "more specialized version" mean? Does it mean override a method?
Leandro Coutinho wrote:I have one doubt about your code. I don't understand how the run method in the LoggingThread class is called.
I know that the run method is executed after the method start is called, but not in this case because the overridden method start doesn't call the method run.
Leandro Coutinho wrote:But the run() method in the Thread class that should be executed, right?
He called the super constructor passing an implementation of Runnable as parameter, that just prints "Doing some useful, long-running unit of work."
So I don't understand how the run() method in the LoggingThread class is called. Please help me.
Leandro Coutinho wrote:But the run() method in the Thread class that should be executed, right?
He called the super constructor passing an implementation of Runnable as parameter, that just prints "Doing some useful, long-running unit of work."
So I don't understand how the run() method in the LoggingThread class is called. Please help me.
Dave Wingate wrote:Calling the start() method on the Thread class starts a new background thread that executes the Thread's run() method:
http://java.sun.com/javase/6/docs/api/java/lang/Thread.html#start%28%29
So what does the Thread's run() method do? The key insight is that, because the Thread was constructed with a Runnable argument, the Thread's run method will call the run() method of the Runnable:
http://java.sun.com/javase/6/docs/api/java/lang/Thread.html#run%28%29
Leandro Coutinho wrote:Why do you think that Thread implementing Runnable is an example of the Template Method? There's no template method.
Leandro Coutinho wrote:I'm creating this topic mainly because of the JFrame class. The Sun's examples always extend JFrame. Why? Just for convenience?
Why instead of use inheritance, they don't have an instance of JFrame?
Paul Clapham wrote:
Leandro Coutinho wrote:I'm creating this topic mainly because of the JFrame class. The Sun's examples always extend JFrame. Why? Just for convenience?
Why instead of use inheritance, they don't have an instance of JFrame?
I think it's historical. That's the way things were done back then. It isn't even any more convenient for a class to extend JFrame instead of having a JFrame instance variable, so I don't think that was the reason.
Quite likely if they were writing the tutorials now, they would have an instance of JFrame (composition) rather than being an instance of JFrame (inheritance). But the original tutorials were written in a simpler time, before the theoreticians of object-orientation started to have the influence which they have today.
Paul Clapham wrote:I think it's historical. That's the way things were done back then. It isn't even any more convenient for a class to extend JFrame instead of having a JFrame instance variable, so I don't think that was the reason.
Quite likely if they were writing the tutorials now, they would have an instance of JFrame (composition) rather than being an instance of JFrame (inheritance). But the original tutorials were written in a simpler time, before the theoreticians of object-orientation started to have the influence which they have today.
Embla Tingeling wrote:Come on now, this is Sun's Hello World example and it has been for a long time,
girl power ... turns out to be about a hundred watts. But they seriuosly don't like being connected to the grid. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|