I would like to call a method for every instance of one of my classes, but have no clue how to go about doing that.
public class demostration{
public void m(){
}
}
demonstration d = new demonstration();
demonstration p = new demonstration();
How can I call the method m so that all instances of demonstration run that method? I.e. so it has the same effect as writing
d.m();
p.m();
Whenever you create a new instance, put it into some type of mutable array. When you want to call the method m of each instance, simply loop through the array of instances, calling m on each instance.