The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
September 2000



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


RE:Concept Problem!!!

Posted by Kishori Sharan on October 01, 2000 at 11:36 PM

Hi Joe
First answer one question .
Are yor defining the int array within constructor? That is, is it a local int array? If yes then you need to define your int array as an instance variable of your class AClass. Because, one AClass object is created you are losing the reference to that array which was defined locally in constructor. One way is that declare an instance variable int[] myArray. Create it in constructor. Define a new method print ( ) with no argument and call the existing print ( int[] array ) from within print ( ) passing the array which is an instance variable
Better define a method which will create the array you are creating in constructor and then it will return that array , so that your code will be like
AClass aa = new AClass ( ) ;
int[] temp = aa.createArray ( 10 ) ;
aa.print( temp ) ;



Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us