Say I have a class with multiple private String variables:
public class Children
{
private String child0, child1;
}
I want to create a SetName method, which would set child0 or child1 to a specified value
So I could do something like this after instantiating Children class:
myChildren.SetName(child0, "Lucy");
How can I pass the private class variable String in a method? How do I code SetName method? I know I could create an array, and pass the element number, but that’s not what I need, not how I want to implement this.
You could store the children in one of
Map‘s implementation.HashMapis appropriate for most cases.