"Your time is limited, so don't waste it living someone else's life"

Why Java support two ways to create a thread?

As you know, Java programming language support programmer two ways to create a thread, different from others language.

  • Extends from class Thread
  • Implement interface Runable

Java language does not allow a class inherit from more than one supper class. But, it allow programmer implement classes. Two above things explain the main question of this post Why Java support two ways to create a thread?

I’ll give you an example:

I have a class named ClassA, then i also have other class named ClassB. And ClassB is the derivative class of ClassA. If i want ClassB also to be a thread. In this case, i can not use the inheritance way, because i can not write:

public class ClassB extends ClassA, Thread{
}//this is wrong way

So i use like

public class ClassB extends ClassA implement Runable{

2 responses to “Why Java support two ways to create a thread?

  1. Nhà cung cấp giải pháp trần nhôm, lam chắn nắng CHLB Đức hàng đầu Việt Nam November 11, 2012 at 8:52 AM

    Terrific work! This is the type of information that should be shared around the internet. Disgrace on Google for no longer positioning this put up upper! Come on over and talk over with my web site . Thank you =)

  2. future garage November 19, 2012 at 12:55 PM

    I came here hunting something else, but this entertained me regardless. Enthusing stuff!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: