• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

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
 
What do you have to say for yourself? Hmmm? Anything? And you call yourself a tiny ad.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic