0
If we initialize an array of a custom class MyClass.java like this MyClass[] myClass = new MyClass[5]; then how can we instantiate member variable of that class through its setters methods?
e.g to instantiate a "name" data member variable of MyClass.java, how can we instantiate this "name" variable.
2 Answers
0
myClass[0] = new MyClass (arg);
and so on...
- 1
Thanks for reply. But I forgot to mention that actually MyClass.java has a default constructor so it can't take any parameter while creating new instance of it. So, finally I have come to following solution:
MyClass[] myClass = new MyClass[5];
myClass[i] = new MyClass();
myClass[i].setName("Person");
where i is the index of element of the array myClass that is being instantiated.