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 Calling constructor twice? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Calling constructor twice?" Watch "Calling constructor twice?" New topic
Author

Calling constructor twice?

shaf maff
Ranch Hand

Joined: Sep 07, 2008
Posts: 180
Hi Guys

Is it possible to call a constructor twice? For example:



Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

Please take the time to choose the correct forum for your posts. This forum is for questions on Servlets.

For more information, please read this.

This post has been moved to a more appropriate forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38033
    
  22
You can call a constructor twice, if it is overloaded. This is how you might do it with a Clock, which is more-or-less the same as an example in the Deitel and Deitel books.Flesh out that class, set up a class with a main method, and try it out.

I hope that answers your question. If you use the keyword this with () like that, it must be the first statement in the constructor.

As far as I know you cannot invoke a constructor on an already-extant object, as you seem to be doing. Nor can you call an object "class," because "class" is a keyword.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38033
    
  22
myself wrote:Flesh out that class, set up a class with a main method, and try it out.


Then find my spelling errors and correct them!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calling constructor twice?
 
Similar Threads
PageContext and jsp:useBean
Building a class which initializes abject like String class?
Passing parameters to init() method
Constructor
init() vs constructor