Click here to Skip to main content
15,891,184 members
Home / Discussions / Java
   

Java

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

Java
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
jschell2-Oct-12 8:46 
AnswerRe: Creating a Thread Pin
Richard MacCutchan2-Oct-12 9:32
mveRichard MacCutchan2-Oct-12 9:32 
GeneralRe: Creating a Thread Pin
Neo101012-Oct-12 20:53
Neo101012-Oct-12 20:53 
GeneralRe: Creating a Thread Pin
TorstenH.2-Oct-12 23:31
TorstenH.2-Oct-12 23:31 
AnswerRe: Creating a Thread Pin
Peter_in_27802-Oct-12 22:05
professionalPeter_in_27802-Oct-12 22:05 
AnswerRe: Creating a Thread Pin
Gowtham Gutha15-Nov-12 7:15
Gowtham 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.