Why this happened, it gives me error in void main
when initializing newString
, this The method StringThread(String, int) is undefined for the type mainThread
? Here is code:
public class mainThread {
public class StringThread implements Runnable {
private int num;
private String text;
public StringThread(String text, int num){
this.text = text;
this.num = num;
}
public void run(){
for(int i = 0; i < num;i++)
System.out.println(i+1+". " + text);
}
}
public static void main(String[] args){
StringThread newString;
newString = StringThread("Java", 30);
new Thread(newString).start();
}
}