Click here to Skip to main content
12,882,639 members (38,819 online)
   

Java

 
QuestionCreating a Thread Pin
CsTreval2-Oct-12 8:17
memberCsTreval2-Oct-12 8:17 
Consider the following code:
public class MyThread extends Thread {
    @Override
    public void run(){
        System.out.println("Testing thread.");
    }
}

public class App 
{
    public static void main( String[] args )
    {
        MyThread thread = new Thread();
    }
}


Why does the syntax checker not accept line 5 in 'App.java' (The one with the MyThread Reference Type)? If MyThread is aThread, then why is it incorrect to create a new Thread out of it? I know I'm supposed to replace it with new MyThread, but why is Thread not allowed? Doesn't 'extend' mean 'inherits all properties etc.'?
AnswerRe: Creating a Thread Pin
jschell2-Oct-12 8:46
memberjschell2-Oct-12 8:46 
AnswerRe: Creating a Thread Pin
Richard MacCutchan2-Oct-12 9:32
mvpRichard MacCutchan2-Oct-12 9:32 
GeneralRe: Creating a Thread Pin
CsTreval2-Oct-12 20:53
memberCsTreval2-Oct-12 20:53 
GeneralRe: Creating a Thread Pin
TorstenH.2-Oct-12 23:31
memberTorstenH.2-Oct-12 23:31 
AnswerRe: Creating a Thread Pin
Peter_in_27802-Oct-12 22:05
memberPeter_in_27802-Oct-12 22:05 
AnswerRe: Creating a Thread Pin
Gowtham Gutha15-Nov-12 7:15
memberGowtham Gutha15-Nov-12 7:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web02 | 2.8.170422.1 | Last Updated 23 Apr 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid