• 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

Compiler Error: Identifier expected

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a simple program. I am getting a compiler error ("Identifier expected") at line 17. Can somebody please explain?
Thanks a ton!!!

public class test {
public static void main(String[] arguments) {
int a = 10, b = 10;
a = a + 100;
b = b + 100;
System.out.println ("Values are:") ;
System.out.println (a);
System.out.println (b);
}

public class pubClass {
int c = 100;
int c2 = c;
System.out.println(c2); //Error: Identifier expected!
}
}
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mehul,
It's throwing that error because the System.out.println( c2 ); statement is not inside a method or an initilization block... so Java has no idea what you are talking about... the only thing that can be outside of a method or initialization block are attribute declarations ( plus optional assignment of that attribute ), and inner classes.
Also, if these classes are in one file together, only one of them should be declared public, and that one should be the one that has the same name as your source code file. ( i.e. if you keep test as the public class call it test.java, if you keep pubClass as the public class call it pubClass.java )
HTH,
-Nate
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic