• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

From main method to contractor, it is possible?

 
Pan Niko
Ranch Hand
Posts: 86
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10508
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
AbdulRab Khan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10508
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic