user2792660
user2792660

Reputation: 37

Calling an array into another array...?

Perhaps I'm not phrasing this correctly, but I have built a class that makes a dynamic array that doubles every time it reaches it's maximum from input. I am now trying to integrate that into another class that will make a list of strings using what I already built in the dynamic array class. Something like:

 public StringList() {
        DynamicArray2 StringList= new DynamicArray2();}

But I know that isn't right because then I can't refer to it for the rest of the class because it will be cut off. Any suggestions?

Upvotes: 0

Views: 65

Answers (1)

frogmanx
frogmanx

Reputation: 2630

I assume I understand what you are saying. You are declaring a variable inside of a class's constructor which, as you said, makes it out of scope with the rest of the class. Try moving the declaration outside of the constructor.

public class StringList {

    DynamicArray2 stringList;        

    public StringList() {
        stringList= new DynamicArray2();
    }

}

Or maybe you just want to have a publicly accessible DynamicArray2 object? Try:

public DynamicArray2 stringList = new DynamicArray2();

Upvotes: 1

Related Questions