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
Post a Comment