GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes From main method to contractor, it is possible? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "From main method to contractor, it is possible? " Watch "From main method to contractor, it is possible? " New topic
Author

From main method to contractor, it is possible?

Pan Niko
Ranch Hand

Joined: Mar 19, 2011
Posts: 86

Hello,

I would like to ask if is possible to use an object that created in main method to the constructor of a class. Or if there is way to do that, to share the same object main method and constructor.

Thank you
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7892
    
  21

Pan Niko wrote:I would like to ask if is possible to use an object that created in main method to the constructor of a class.

If your question is: 'can you use an object created in a main() method IN the constructor of the same class', the answer is: no.

Or if there is way to do that, to share the same object main method and constructor.

Again, if I understand you right: no.

Perhaps it would be better to explain what you want to do, rather than speculating about how you're going to do it.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
AbdulRab Khan
Greenhorn

Joined: Nov 11, 2011
Posts: 7
Yes you can share the same object created in the Main method to the constructor, please see the following example:



[Edit - fixed code tags - MB]
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7892
    
  21

AbdulRab Khan wrote:Yes you can share the same object created in the Main method to the constructor, please see the following example:

Beg pard. AbdulRab is quite right. I was thinking about something completely different.

Winston
 
GeeCON Prague 2014
 
subject: From main method to contractor, it is possible?