Is it that in one java source file ( .java file ) there should be only one class with access modifier " public " or a java source file can have as many " public " classes as possible ?
Yes, the rule is that you must have a maximum of one top-level public class per source file, and that, if you have one, the source file name must be the same as the public class.
A file can have as many top-level package-private classes as you like. However, I think it is bad practice to use this lattitude. I think that, even when classes are package-private, you should limit yourself to one top-level class per source file, which should be named after the class.
As already mentioned, nested and inner classes have no restriction as to their number, even when public, and do not affect the source file name.
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.<br /> <br />#:^P
prathibha ananthapadmanabha
Greenhorn
Joined: Jul 12, 2007
Posts: 16
posted
0
Dear All ,
Thank you so much for the clarifications given . So to conclude , it is that one java source file must have only one public class with the same name as the name of the source file .
Regards, Prathibha.
Satya Maheshwari
Ranch Hand
Joined: Jan 01, 2007
Posts: 359
posted
0
So to conclude , it is that one java source file must have only one public class with the same name as the name of the source file .
Just a minor change: So to conclude , it is that one java source file must have only one top-level public class with the same name as the name of the source file .
prathibha ananthapadmanabha
Greenhorn
Joined: Jul 12, 2007
Posts: 16
posted
0
could you please clarify what it means by " top -level " public class , it means that other public classes are possible in a java source file .
Regards, Prathibha.
Satya Maheshwari
Ranch Hand
Joined: Jan 01, 2007
Posts: 359
posted
0
could you please clarify what it means by " top -level " public class , it means that other public classes are possible in a java source file .
By "Top-level", I meant class which is not an inner class. Inner-classes are the classes as members inside a top-level class. These inner-classes can be public along with their top-level class. Please see the example I quoted in my earlier post where this is done.
prathibha ananthapadmanabha
Greenhorn
Joined: Jul 12, 2007
Posts: 16
posted
0
Hi
Now it is clear . Thank you for the clarification .