0

When we create ArrayList such

 ArrayList<String> obj = new ArrayList<String>();

We are creating a ArrayList of type String and a reference to this object by the name obj. What about this?

 ArrayList<Node> obj;

A ArrayList of type Node with only the reference that is pointing to null? What does this statement look like in memory?

Example:

import java.util.List;

public class PackageNode {

private String value;

private List<PackageNode> children;

public PackageNode(String value) {

this.value = value;

}

public String getValue() {

return value;

}

public void setValue(String value) {

this.value = value;

}

public List<PackageNode> getChildren() {

return children;

}

public void setChildren(List<PackageNode> children) {

this.children = children;

}


}

Assume the code above is a Node class for a PackageTree, What does this mean?

List<PackageNode> children;
15
  • Depends if it's class or method . Commented Oct 25, 2017 at 17:12
  • Node is a class...! Commented Oct 25, 2017 at 17:13
  • That's irrelevant. Where is the variable declared? Commented Oct 25, 2017 at 17:14
  • See the edit... Commented Oct 25, 2017 at 17:20
  • If it's declared at the class level, it will be null by default. Commented Oct 25, 2017 at 17:21

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.