• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

compilation fails <identifier expected>

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Dear Friends
Compilation is failed at line number 18.but if i put this LOC in a method as shown in commented code it is working.please clarify me why so it is happening.
Thanking you.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Compilation is failed at line number 18.but if i put this LOC in a method as shown in commented code it is working.please clarify me why so it is happening.




Question: What is Java supposed to do, with code that is not in a method, constructor, or initializer? And is not declaring anything?

Henry
 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code was working fine when that particular statement was inside a method because Java compiler expects it to be there. Putting such statements anywhere in a class (except in the constructors, initializer blocks, methods) does not make sense. Think as it is kind of problem as the JVM will not understand when to execute such statements, thats why compiler shows errors.
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Makes sense. Thats right!!!

 
aruna dabas
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Henry Wong for reminding me very sensible thing.I forgot this as at that time i was concentrating only on that LOC(assuming it is inside main)forgot to see that it is in a class not inside the main method.my mistake.Thanks again.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic