• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java program file name question  RSS feed

 
Varun Chopra
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created following class:

class Student
{
//some code here
}

and saved it in XYZ.java

I compiled it and got Student.class file, which I was able to run with "java Student"

My question is, why do every book/tutorial say we have to save the program in <classname>.java file? I was able to run it by saving it in XYZ.java.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All public classes have to be created in a file with the same name as the class. Your class isn't public, so you can have any file name you want.
 
Varun Chopra
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok great, it's clear.....
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!