java - From static main method in same outer class like inner class, can't access to constructor from inner class -


why happened, gives me error in void main when initializing newstring, the method stringthread(string, int) undefined type mainthread ? here 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 = 0; < num;i++)                 system.out.println(i+1+". " + text);         }      }      public static void main(string[] args){         stringthread newstring;         newstring  = stringthread("java", 30);         new thread(newstring).start();     }  } 

new keyword missing in initialization , that's why considering method , not constructor , it's inner class should be. (suggested stultuske)

mainthread obj = new mainthread(); stringthread newstring = new obj.stringthread("java", 30);//new keyword missing 

please read following answer understand why need access inner class,


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -