• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

default or public ?

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://faq.javaranch.com/view?ScjpFaq#classInFile
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks All
 
Ranch Hand
Posts: 257
Hibernate Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic