File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Empty Private Constructor Class: Why? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Empty Private Constructor Class: Why?" Watch "Empty Private Constructor Class: Why?" New topic
Author

Empty Private Constructor Class: Why?

Tom Marler
Greenhorn

Joined: Jul 05, 2011
Posts: 1
I am new to this forum, thanks for providing the platform! I have been starting to study Java and ran into a line of code from an example out of a book I could not make sense of, maybe somebody has an idea.



Why did they specify a private Constructor which is empty? They did it both for the outer class and also for the inner.

Thanks!
Tom
Dan Din
Greenhorn

Joined: Jun 06, 2011
Posts: 12
Welcome, Tom!

I think the example want to demonstrate the relation between the Outer and Inner classes - in my code, i can create an instance to the outer class from the inner class (line 8), and vice-verse (line 18), even the constructor are private and cannot be accessed from outside.

I look forward for other explanation.

D.


Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Tom Marler wrote:


Why did they specify a private Constructor which is empty? They did it both for the outer class and also for the inner.


the whole purpose of this idiom is you cant create an object as well as cant subclass for both Outer and Inner classes from other classes.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

And Welcome to JavaRanch
Unnar Björnsson
Ranch Hand

Joined: Apr 30, 2005
Posts: 164
This class is probably designed to be a singleton or static method provider, in either case it should not be instantiated by outside call, therefore the default constructor is overridden as private.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Unnar Björnsson wrote:therefore the default constructor is overridden as private.


I think, you meant *marked* as private. constructor can not be overridden
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Empty Private Constructor Class: Why?
 
Similar Threads
inner class
private constructors
Abstract class with private constructor (why compiles if I can't extend)?
outer class from inner class
java bean's constructor