• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

access modifier for constructor ?

 
mark stone
Ranch Hand
Posts: 417
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey that's a really good question Mark! I would guess it's public, but I don't know for sure!

Rob
 
Tarik Makota
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i would say it is public.
public Object() is constructor for Object class
 
Ruchi Kolla
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!

Rob

For sure its public. You can create instance of the class from any package.
 
Sai Patnala
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic