Padma Latha

Greenhorn
+ Follow
since Oct 05, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Padma Latha

hi sidiqui.
yes you were right when you said that compiler will generate the default constructor, if you dont provide one. But I got JLS extract for you to help clear the contention:




8.8.10 Preventing Instantiation of a Class
A class can be designed to prevent code outside the class declaration from creating instances of the class by declaring at least one constructor, to prevent the creation of an implicit constructor, and declaring all constructors to be private. A public class can likewise prevent the creation of instances outside its package by declaring at least one constructor, to prevent creation of a default constructor with public access, and declaring no constructor that is public.

Thus, in the example:



the class ClassOnly cannot be instantiated, while in the example:



the class PackageOnly can be instantiated only within the package just, in which it is declared.

Hope it clears your question.
Padma.

Originally posted by kayanaat sidiqui:
Hi there,
well i was just going through the code for singleton pattern. In that code i got that constructor was private. And that is my problem. In simple sense, what java says that if you consider access specifier, you can widen, not narrowing. Now if we do not provide any constructor to a class, java simply provides a default constructor, and we can easily instantiate the class outside of that class, which proves that default constructor is not private. So in case of singleton pattern how we can do narrowing?
Please help me out.

Thanks in advance.

[edit]Add code tags. CR[/edit]
[ October 05, 2008: Message edited by: Campbell Ritchie ]
15 years ago