I created a class in a file called Pq which is an object having Strings like this
public class PQ {
String ec;
String com;
String ai[3];
String answers[3];
}
Now I want to make an array of this object of length 10.
Then fill each of the individual elements like ec,com with data as per my requirement with a for loop like
for(i=0;i<10;i++)
pq.ec=25;
How to do this?
I also want to fill ai,answers. How to access those elements
I tried ArrayList but I am able to add the whole object but unable to add individual items
Please help me out
In your PQ class define getters and setters to manipulate fields of your objects safely conforming to the principle of encapsulation.
To populate an array of PQ objects use a code similar to this:
Note that you can fill each field of individual objects by using the appropriate setter method and valid argument(s).