Click here to Skip to main content
       

Java

 
QuestionCreating a Thread PinmemberCsTreval2-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 Pinmemberjschell2-Oct-12 8:46 
AnswerRe: Creating a Thread PinmvpRichard MacCutchan2-Oct-12 9:32 
GeneralRe: Creating a Thread PinmemberCsTreval2-Oct-12 20:53 
GeneralRe: Creating a Thread PinmemberTorstenH.2-Oct-12 23:31 
AnswerRe: Creating a Thread PinmemberPeter_in_27802-Oct-12 22:05 
AnswerRe: Creating a Thread PinmemberGowtham Gutha15-Nov-12 7:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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
Web01 | 2.8.140814.1 | Last Updated 18 Aug 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid