Results 1 to 6 of 6
Thread: Constructors
- 10-19-2010, 06:13 AM #1
Member
- Join Date
- Oct 2010
- Posts
- 14
- Rep Power
- 0
- 10-19-2010, 06:22 AM #2
You can have classes that cannot be "created" by other methods. These are used for classes with only static members.
Additionally, you can have private classes that can only be created internally. These are called singletons. Read more on such design patterns here.
- 10-19-2010, 10:14 AM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,457
- Rep Power
- 16
Or if you have an inner class that you want to expose to other classes, but you only want to allow it to be created inside the main class.
eg:
MyInnerClass can only be instantiated within an object of MyMainClass.Java Code:public class MyMainClass { public class MyInnerClass { private MyInnerClass() { } } }
- 10-19-2010, 07:58 PM #4
Even if it's public, you cant instantiate it from another class... can you? I've tried this before with no success.
- 10-19-2010, 08:04 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,399
- Blog Entries
- 7
- Rep Power
- 17
- 10-20-2010, 12:10 AM #6
Similar Threads
-
Need help with constructors
By tpfaff in forum New To JavaReplies: 10Last Post: 10-22-2010, 04:33 AM -
Constructors?
By annna in forum New To JavaReplies: 3Last Post: 01-27-2010, 10:51 PM -
constructors?
By shroomiin in forum New To JavaReplies: 4Last Post: 10-13-2009, 02:14 PM -
Constructors
By new2java2009 in forum New To JavaReplies: 5Last Post: 08-18-2009, 06:46 AM -
constructors
By khamuruddeen in forum New To JavaReplies: 2Last Post: 12-01-2007, 03:15 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks