aspose file tools*
The moose likes Beginning Java and the fly likes accessing variables of other classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "accessing variables of other classes" Watch "accessing variables of other classes" New topic
Author

accessing variables of other classes

madhup narain
Ranch Hand

Joined: Dec 14, 2004
Posts: 148
hi

can someone tell me how to access a variable of another class. without inheritence without modifying the return parameters of method getData().
i want to get the value 10 stored in str_int







Money for nothing and Java for Free
SCJP, SCWCD
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3704
    
    5

Unless there's more code, it doesn't look the value of like str_int gets saved, the input gets assigned to Integer(10) and then thrown away since you can't reassign an input object's reference value.


My Blog: Down Home Country Coding with Scott Selikoff
Sachin Dimble
Ranch Hand

Joined: Dec 07, 2005
Posts: 100
Mahup, u can make str_int as instance variable of class Data after calling getData() can access the changed value of str_int!

With Best Regards,
Sachin Dimble
Adam Richards
Ranch Hand

Joined: Nov 03, 2005
Posts: 135
Better way is to add a getter function to the data class that returns the variable value you want (e.g., getStrInt()).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: accessing variables of other classes