• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Identifier expected

 
Banaja Bhaduri
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While compiling the flowing code I get a cmpiler error 'identifier expected at i=7'.
class test
{int i, j;

i = 7;
j = 10;


public static void main(String arg[])
{int i = 10;
int j = 7;
System.out.println(i+j);
test basis = new test();
System.out.println(basis.i);
}
}
Could anyone please explain this, when 'i' itself is an identifier.
 
Randall Twede
Ranch Hand
Posts: 4481
3
Java Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See this thread. We just went over that. http://www.javaranch.com/ubb/Forum33/HTML/001643.html
basically you can only do a simple assignment from inside a method or constructor.
I am going to close this thread.
[This message has been edited by Randall Twede (edited February 13, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic