This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes access modifier for constructor ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "access modifier for constructor ?" Watch "access modifier for constructor ?" New topic

access modifier for constructor ?

mark stone
Ranch Hand

Joined: Dec 18, 2001
Posts: 417
what is the "access modifier" for the no-argument constructor provided by the compiler when no constructor is explicitly provided in the code

public, is always "friendly",always defaults to the access modifier provided for the class or it depends on the compilation options of javac
Rob Ross

Joined: Jan 07, 2002
Posts: 2205
Hey that's a really good question Mark! I would guess it's public, but I don't know for sure!


SCJP 1.4
Tarik Makota

Joined: Jan 29, 2002
Posts: 23
i would say it is public.
public Object() is constructor for Object class
Ruchi Kolla

Joined: Jan 24, 2002
Posts: 19
Originally posted by Rob Ross:
Hey that's a really good question Mark! I would guess it's public, but I don't know for sure!


For sure its public. You can create instance of the class from any package.
Sai Patnala
Ranch Hand

Joined: Jan 09, 2002
Posts: 60
Access modifier for the default constructor is same as the access modifier given to the class.
So if a class has public access, access modifier for default constructor is also public.
In no case a top level class can be protected nor private, so there is no way default constructor be protected nor private.
But we must understand that user defined default constructor can be private, in case you want to implement Singleton pattern.
[ January 30, 2002: Message edited by: sai k patnala ]

I agree. Here's the link:
subject: access modifier for constructor ?
jQuery in Action, 3rd edition