aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Use of protected construtor? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Use of protected construtor?" Watch "Use of protected construtor?" New topic
Author

Use of protected construtor?

Thiru Thangavelu
Ranch Hand

Joined: Aug 29, 2001
Posts: 219
Why constructor is declared with different modfiers? I know that constructors are not inherited and what is the use to declare with diff. modifiers?


Thanks,<br />Thiru<br />[SCJP,SCWCD,SCBCD]
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
A private constructor prevents the class from being instantiated (see the Math class). A class with protected constructors could only be instantiated by a child of that class or by a class within the same package as that class.
jls:

A protected constructor of an object may be accessed from outside the package in which it is declared only by code that is responsible for the implementation of that object.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Thiru Thangavelu
Ranch Hand

Joined: Aug 29, 2001
Posts: 219
Thanks Paul, but most of the constructors are public(to be accessed anywhere) or default(to be accessed in the same package). Isn't?
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Yes, most are.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Use of protected construtor?
 
Similar Threads
Splitig integers
not equal too & or operator????
Posting to bump up my count...
Converting Xml to Java Object
Constructing overloading