• 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

class name comparison with file name

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I typed the below code in a file called test.java
class x
{
public static void main(String args[])
{
System.out.println("In Main");
}
}

No Errors occurred during compilation and indeed a class (x.class) was created.
Error was reported only during runtime
(java test).
Isn't the check for (NAME OF JAVA FILE SHUD MATCH CLASS NAME) done during compilation??
(When I made it public class x with the rest of the code same, it gave compilation error saying that x shud be stored in a file x.java )
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the class within the file is declared public then the file name MUST be the same as the class name, otherwise you are free to name your file as you see fit
 
reply
    Bookmark Topic Watch Topic
  • New Topic