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
Posted by Kishori Sharan on October 01, 2000 at 11:36 PM
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 ) ;