• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

default or public ?

 
niku shah
Ranch Hand
Posts: 43
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

In K&B book some mock exam questions ,

class declarations does not contain public specifier ,
so isn't it a mistake ?

what i mean is it may be assumed that class specifier is public ,
as we have to save file name with public class name.

and also options doesn't contain abt public class specifier ,
as there should be one public class in a file name to be executed.


Thanks

Nikesh
 
Gowher Naik
Ranch Hand
Posts: 643
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There can be max one public class per java file.
If there are two or more classes in a java file then name of java file and
public class should be same.
if there are two are more non public classes in java file
then there is no rule applied on naming on java file compare to class file.
 
wise owen
Ranch Hand
Posts: 2023
 
Jay Suttiruttana
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class that does not have a declare modifier automatically gets "default" modifier. So your class can either have public or default access modifier.
 
niku shah
Ranch Hand
Posts: 43
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks All
 
Srinivas Kalvala
Ranch Hand
Posts: 257
Firefox Browser Hibernate Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Its not mondator, atleast one class should be public in single source file, but there can be only one public class allowed and source file name must match it.

If public is not specified then default will be assumed.

Remember , there are only 2 modifiers are present for class, public & default.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic