wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Can we return null value from constructor of Object ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Can we return null value from constructor of Object ?" Watch "Can we return null value from constructor of Object ?" New topic
Author

Can we return null value from constructor of Object ?

Fidel Edwards
Ranch Hand

Joined: Mar 19, 2008
Posts: 231
Hello Members,

Just tell me !

Can we return null value(or any value) from constructor of Object ? As far as I know we can't .So please tell me Am I right ?


Thanks In Advance !!



God Gave Me Nothing I Wanted, He Gave Me Everything I Needed.
OCPJP6
Sona Patel
Ranch Hand

Joined: Mar 30, 2009
Posts: 75
You are right Ashish...

We can not return any value from constructor...

Regards
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

A constructor does not return anything; the "new" operator returns an object that has been initialized using a constructor.

If you really want a constructor that may return null, perhaps you should check out the factory method pattern. A short example:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Fidel Edwards
Ranch Hand

Joined: Mar 19, 2008
Posts: 231
Rob Prime wrote:A constructor does not return anything; the "new" operator returns an object that has been initialized using a constructor.

If you really want a constructor that may return null, perhaps you should check out the factory method pattern. A short example:


Thanks Rob !!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can we return null value from constructor of Object ?
 
Similar Threads
Generic clone/equals Methods
Costructor return type?
Lookup key in HashTable
How to interpret results of println when printing user defined object
destroying objects