java - Type mismatch error: Cannot convert from Player to Thread -


how go making multiple threads of object?

i have class constructor player(string, int, int). now, in main, want create multiple player objects use threads.

i tried making array of these objects

thread[] player= new thread[numberofplayers];     (int = 0; < numberofplayers; i++)     {        player[i] = new player("default", 0, (i + 1));     } 

but 'type mismatch error: cannot convert player thread'.

i want create these threads in loop because every time program runs, there random number of players. threads need access list of information corresponding values given each character (string, int, int) , update them 1 @ time. suggestions?

unless character subclass of thread, can't put character objects thread[]. true objects--you can't treat object of 1 type (say, b) though type (say, b) unless b extends a.

class {     // empty base class }  public class b {     public static void main(string[] args) {         b b = new b();         a[] arrayofas= new a[1];         arrayofas[0] = b; // compile-time error! b not object!     } } 

vs.

public class b extends { // b subclass of     public static void main(string[] args) {         b b = new b();         a[] arrayofas= new a[1];         arrayofas[0] = b; // works fine     } } 

personally, doesn't sound need threads. aware of what thread class for? why not make array out of objects are? other things well: i'd rename character, since that's class in standard library. you'll compile error if try name char, because identifier reserved char primitive type.

player[] players = new player[numberofplayers]; 

Comments