Forums Register Login

public class filename????

+Pie Number of slices to send: Send
I am working through several examples in a Java book. Why does the name of my program file have to match the name of my public class. I have other file with class that don't match the file name.
Thanks!
Mark
+Pie Number of slices to send: Send
Well, for one, that is the way the java compiler works. And another reason is this is just good design. It makes sense that your .class file really be the name of your CLASS.
What do you mean you have other files where the class names don't match the file name?
I would suspect 2 things.
1. They won't compile
2. You are talking about inner classes. So you would still have your main Class that would be the same name as your File.
+Pie Number of slices to send: Send
A public class must be in a file of the same name. You can put other classes in the same file if they are not public.
Everybody's invited. Even this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 849 times.
Similar Threads
Source File declaration rule in java
Naming a java file?
declaring variables
Simple question on Applet
why should the class name and the notepad name should be same?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 02:54:49.