aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Constructor?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Constructor??" Watch "Constructor??" New topic
Author

Constructor??

srikanth reddy
Ranch Hand

Joined: Jul 28, 2005
Posts: 252
hi frnds
i have a simple doubt i.e can a constructor have an access modifier other than what class has ???
coz i read some where that the constructor has the same access modifier as that of class....

please help

srikanth


Thanks & Regards<br /> <br />-Srikanth
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
Yes it can . This of a singleton class whose c'tor is private. It's also a method in a class but a special method without return value.
[ September 23, 2005: Message edited by: Srinivasa Raghavan ]

Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Steve Morrow
Ranch Hand

Joined: May 22, 2003
Posts: 657

i have a simple doubt i.e can a constructor have an access modifier other than what class has ???
Absolutely. Class access modifiers may be public or default (package). Constructor access modifiers may be public, protected, default, or private.
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
And this is about the default C'tor.
From JLS:
If a class declares no constructors then a default constructor, which takes no arguments, is automatically provided. If the class being declared is Object, then the default constructor has an empty body. Otherwise, the default constructor takes no arguments and simply invokes the superclass constructor with no arguments. If the class is declared public, then the default constructor is implicitly given the access modifier public. Otherwise, the default constructor has the default access implied by no access modifier (�2.7.4).
Steve Morrow
Ranch Hand

Joined: May 22, 2003
Posts: 657

Trail: Learning the Java Language - Controlling Access to Members of a Class
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
Hi,

yes you can...



Hope you got it..

Regards
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Constructor??