• 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

Error message concerning public modifier

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there again!
I am wondering about this strange thing about using public modifier in my classes and error messages afterwards when the files being compiled.
Like, let's say, my code look like this
public class A {
}
public class Tester {
public void main(String args[]){
}
}
Error message is:
C:\javasert\JavaSertHarj\src\JavaSertifikaatti\JC16102003.java:8: class A is public, should be declared in a file named A.java
public class A {
^
C:\javasert\JavaSertHarj\src\JavaSertifikaatti\JC16102003.java:11: class Tester is public, should be declared in a file named Tester.java
public class Tester {
I am not getting the point. Pls could anyone help me with this?
Thanks!
-janne-
 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
Each java source file should contain only 1 public class, so change your file in a way that there is only 1 public class to remove the error.
hope this helps,
bye
 
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
first of all, you can't diclare two public classes in the same file. And second of all, your file name must be the same as the public class name (in your case A).

Hope this helps
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
have any one public class and name the file by that
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic