• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interface Code:problem:need to resolve it

 
Deepak Lal
Ranch Hand
Posts: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,
I have the below Java code.



Im compiling this program as below and getting the error as shown below.
why am i getting the below error <identifier> expected.





Please guide me /suggest me whats wrong with the above piece of code.

Help provided will be highly appreciated.

--
Deepak Lal
 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are trying to initialize a field in the class body. This is not allowed in a separate statement. Either move it with the declaration or move it into an initializer block

 
Rob Spoor
Sheriff
Pie
Posts: 20492
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This has nothing to do with the interface. The problem is that you are trying to put statements outside of a method or (static) initializer.

Remember, all a class can contain are declarations (fields, constructors, methods, inner classes / interfaces / enums) and (static) initializer blocks. Any regular code does not belong there.

You can quite easily fix your code by combining the declaration and statement into one:
 
Deepak Lal
Ranch Hand
Posts: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your valuable input and efforts for fixing this piece of code.
Thanks Ankit and Rob.



--
Deepak Lal
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic