aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes how to transfer data in a object to another class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "how to transfer data in a object to another class" Watch "how to transfer data in a object to another class" New topic
Author

how to transfer data in a object to another class

thejaka samarakoon
Ranch Hand

Joined: Jul 20, 2010
Posts: 56
how to pass method local object(object created in the method) to work as a parameter of a another class's constructor(same package)as a data?
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

thejaka samarakoon wrote:how to pass method local object(object created in the method) to work as a parameter of a another class's constructor(same package)as a data?


How do you otherwise pass the references to methods? Even constructor is one such method.


Mohamed Sanaulla | My Blog
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

thejaka samarakoon wrote:how to pass method local object(object created in the method) to work as a parameter of a another class's constructor(same package)as a data?


Pass a reference. Or if immutability is a problem, pass a deep copy of the object


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
thejaka samarakoon
Ranch Hand

Joined: Jul 20, 2010
Posts: 56

Thanks for the help.Can you give a solution
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

You cannot since it is a local variable and the main method takes String[] args.

I can think of an answer, but this does not seem anything to do with SCJP. Looks like Swing homework to me.
thejaka samarakoon
Ranch Hand

Joined: Jul 20, 2010
Posts: 56
Thanks.Mr Bates.I'll post in the swing forum
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3088
    
  40

thejaka samarakoon wrote:I'll post in the swing forum

No, please. Since this is not related to Swing/AWT, please continue the discussion here.

thejaka samarakoon wrote:How to get the rt object to the below code

As Deepak has already pointed out, you can't get rt object, as it resides in another local scope.
OK, if I spill the beans over here, you need to have a static variable in the class that holds a reference to that 'rt object'.


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to transfer data in a object to another class