File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes instantiation again Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "instantiation again" Watch "instantiation again" New topic

instantiation again

Nazma Panjwani

Joined: Jan 17, 2010
Posts: 17
Thank you guys........I was just curious as to how references worked....that's all..........I just used the Mammal class as an example.....
Some while back, I was working w/ arrays, and was trying to call a method that would change the size of an existing array...this method existed in a different class so I had to pass the array(whose size I wanted to change) as a parameter. Inside the method, I defined a temporary array (bigger array), copied all the values from the array that was passed, and then simply pointed the array (formal parameter) to the temp array. But ofcourse, the original array (actual parameter) did not point to the temp array (the bigger array). I figured out another way.....but then I became curious as to if there was a way in java which would allow this.....

By creating aliases, I can certainly change the state of an object, but I can't make one point to a new object (and have the other one automatically point to the new object as well).

Thanks for all your help.
W. Joe Smith
Ranch Hand

Joined: Feb 10, 2009
Posts: 710
No problem .

Just an FYI, if you need to do that again (expand the size of your array) you can use something like an ArrayList, which increases its size as needed with no work on your part.

When I die, I want people to look at me and say "Yeah, he might have been crazy, but that was one zarkin frood that knew where his towel was."
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
well what you want to do is pretty much this ...

or if you want to be generic

however, Arrays.copyOf already does that for you ;-)

JDBCSupport - An easy to use, light-weight JDBC framework -
Nazma Panjwani

Joined: Jan 17, 2010
Posts: 17
Thanks guys,

Joe it was an assignment, so I had to come up with my own class.....and array........couldn't use ArrayList,
Sebastian, that is exactly how I did it after discovering my original method didn't work......
I agree. Here's the link:
subject: instantiation again
It's not a secret anymore!