Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Programmer Certification (OCPJP)
Constructors
Ciaran O Keeffe
Greenhorn
Posts: 1
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I came accros a question in your
java
rule round up. Which says that a constructor can be declared private. How does this work, I mean how can you create an object from a Constructor declared like this?
rajesh godbole
Ranch Hand
Posts: 31
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
You speak out the answer. If you don't want others to instantiat your class, you can make the constructor private. E.g. Math class.
Rajesh Godbole
vidya sagar
Ranch Hand
Posts: 580
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Yes constructor can be declared private
1 -- Once constructor is private we can create object only within that class,we cannot create object outside of the class
2 -- Class cannot be extended also..
Pedro Lobato Sena
Greenhorn
Posts: 16
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
U can create an object using a static method of the class that has the private method.
SCWCD<br />SCJP<br /> <br />Pedro Henrique Lobato Sena
faisal usmani
Ranch Hand
Posts: 139
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
A very good example is
Singleton Class
Don't get me started about those stupid
light bulbs
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
inner classes
A question on constructor
Constructord
Private Class????
Anonymous Class
More...