Two Laptop Bag*
The moose likes Beginning Java and the fly likes start() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "start()" Watch "start()" New topic
Author

start()

kumarth ravi
Ranch Hand

Joined: Jun 01, 2007
Posts: 48
I have a some basic doubt.



My doubt is:
-------------
here start() is inherited from the threadclass.It will access only the methods and variables of it's class.Here how this start() method calls the subclass MyThread's run() method.
I think it calls only the superclass run method();


with regards.
ravi
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
No, it will call the run method that is defined in class as far down in the class hierarchy of the current object as possible. So if your MyThread subclass overrides the run method, that one will be called. That's the whole purpose of polymorphism.

This behavior actually isn't specific to threads at all - moving to Java in General...


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
frens java
Greenhorn

Joined: Oct 16, 2006
Posts: 1
The start() in java.lang.Thread calls a native method start0(), which sets up requisite datastructure for thread. Once native method is done with what it has to do, it calls the run() in java.lang.Thread.
java.lang.Thread.run() sees if the subclass of Thread overrides run() and executes the overriden method.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by frens java:

java.lang.Thread.run() sees if the subclass of Thread overrides run() and executes the overriden method.


Actually it's not Thread.run() which looks for it, but the JVM which looks for whether the method is overridden. Thread.run() actually does nothing at all (take a look at its source code that comes with the JDK).
kumarth ravi
Ranch Hand

Joined: Jun 01, 2007
Posts: 48
thank you for your answers.

with regards
ravi
kumarth ravi
Ranch Hand

Joined: Jun 01, 2007
Posts: 48
thank you for your answers.

with regards
ravi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: start()