This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Protected Constructed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Protected Constructed" Watch "Protected Constructed" New topic

Protected Constructed

abin joy
Ranch Hand

Joined: Jul 29, 2008
Posts: 35
What does a protected constructor for a class mean?
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

It means that constructor cannot be used by a class outside that particular package (unless the calling class extends the class with the protected constructor).

Why you might use a protected constructor is harder to explain. One possible implementation could be in some sort of creation pattern where all the classes that participate in the pattern sit in one package and you don't want classes outside this calling the constructor directly.
[ September 02, 2008: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Have you checked out Aspose?
subject: Protected Constructed
jQuery in Action, 3rd edition