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

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -