Forums Register Login

Only one public class in one file in Java

2
+Pie Number of slices to send: Send
Why can't more than 1 public classes be present in a single JAVA file?
1
+Pie Number of slices to send: Send
Because that's just how the designers wanted it to be.

They probably did it to reduce the amount of time that compilers need to find out what file a class description is in.
1
+Pie Number of slices to send: Send
 

Stephan van Hulst wrote:They probably did it to reduce the amount of time that compilers need to find out what file a class description is in.


The JLS supports your insightful comment

This restriction makes it easy for a Java compiler to find a named class within a package.


For example, the source code for a public type wet.sprocket.Toad would be found in a file Toad.java in the directory wet/sprocket, and the corresponding object code would be found in the file Toad.class in the same directory.

 
+Pie Number of slices to send: Send
 

For example, the source code for a public type wet.sprocket.Toad would be found in a file Toad.java in the directory wet/sprocket, and the corresponding object code would be found in the file Toad.class in the same directory.



Or:
- the source code for a public type wet.sprocket.Toad would be found in a file sprocket.java in the directory wet, and the corresponding object code would be found in the file sprocket$Toad.class in the same directory.
- the source code for a public type wet.sprocket.Toad would be found in a file wet.java in the . directory, and the corresponding object code would be found in the file wet$sprocket$Toad.class in the same directory.

+Pie Number of slices to send: Send
And the dev who named their classes either 'wet' or 'sprocket' would be found out on the kerb, holding the contents of their desk in a cardboard box.
;)
+Pie Number of slices to send: Send
 

Dave Tolls wrote:And the dev who named their classes either 'wet' or 'sprocket' would be found out on the kerb, holding the contents of their desk in a cardboard box.
;)


The problem is java and javac don't know about this.
+Pie Number of slices to send: Send
A wet cardboard box, surely.
+Pie Number of slices to send: Send
Possibly with some sort of amphibian in it.
+Pie Number of slices to send: Send
A newt?
Something must be done about this. Let's start by reading this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 459 times.
Similar Threads
Why only one public class per file??
One Public Class Per Source File?
private class
What does this mean?
Duplicate Characters
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 06:47:45.