| Author |
Public class
|
Jenny raj
Ranch Hand
Joined: May 19, 2005
Posts: 57
|
|
I have a doubt reg access specifier. If a class is declared as public will it hold the same for its constructors and its methods implicitly? thanks
|
 |
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
|
|
|
No, they will all have default (package) access modifiers. Exception for a defaulted implicit no argument constructor - that will have an implicit public constructor if the class is public.
|
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
|
 |
Ramesh Mangam
Greenhorn
Joined: May 03, 2005
Posts: 13
|
|
Hi Jenny, Class declaration has nothing to do with method declaration. You have to expicitly give access modifiers to constructors or methods. However, there is one exception. If we do not write any constructors ourselves, in that case the compiler provides us with default constructor and the access modifier for that constructor will be same as the its class's access modifier. Also, a class can have only public or default access levels.
|
 |
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
|
|
"Also, a class can have only public or default access levels." For top-level classes, yes. But not nested classes.
|
 |
Ramesh Mangam
Greenhorn
Joined: May 03, 2005
Posts: 13
|
|
|
Yes. I should have been more specific. Thanks Barry.
|
 |
Jenny raj
Ranch Hand
Joined: May 19, 2005
Posts: 57
|
|
Thanks folks,that was a clear explanation
|
 |
 |
|
|
subject: Public class
|
|
|