static - Java ClassFormatError: Method "<error>" class has illegal signature -


im getting error on line 1 , line 2. line 1 says illegal start of expression. dont understand why line 1 illegal

public class myart {     public static void main(string argv[]) {         myart m = new myart();         m.amethod();     }      public void amethod() {         static int i; // line 1         system.out.println (i); // line 2     } } 

you cannot decalre static field inside method:

public class myart {          public static void main(string argv[]) {               myart m = new myart();               m.amethod();         }         //you can have non-static method since          //calling through myart object m         public void amethod() {                int i=0; // removed static, otherwise program won't compile               system.out.println (i); // line 2, if not initialized compilation fail variable refrenced          }     } 

Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -