How to spawn multiple monsters from a single class? Can store it in an array, ok, but later on, how can I paint it? Because if I do:enemy = new Enemy();enemy2 = new Enemy();I create two instances of the object, but after how can I paint it?I use:g2d.drawImage(Enemy.getImage(), Enemy.getX(), Enemy.getY(), this);But obviously it uses the class, not the variable.Images will not be overlaid because coordinates are random.Enemy's structured like:public class Enemy {static Random randomGenerator = new Random();private int x;private int y;private Image image;private int dx;private int dy;private int i;private int strength=10;private static int hp=100;public String EnemyP = /image/cazzillo_base_definitivo_000.png;public Enemy() {    //Set skin and enemy position    ImageIcon ii = new ImageIcon(this.getClass().getResource(EnemyP));    image = ii.getImage();    x = randomGenerator.nextInt(1024);    y = randomGenerator.nextInt(700);}public int getX() { //Get function    return x;}public int getY() {    return y;}public Image getImage() {    return image;}public void move() {    //Movement with delay    if(i==6){    x += dx;    y += dy;    }}public void follow () { //Function that follow the main character    if (Cazzillo.getX()>x)  //Cazzillo it's the character class        dx=1;    else if (Cazzillo.getX()<x)        dx=-1;    else        dx=0;    if (Cazzillo.getY()>y)        dy=1;    else if (Cazzillo.getY()<y)        dy=-1;    else        dy=0;    if(i<6)        i++;    else        i=0;}public void attack () { //Attack function not implemented yet}public void attacked (){    //Function that is activated when enemy's attacked    hp -=Cazzillo.getS();    if (hp<=0)          death();}public void death (){        x=randomGenerator.nextInt(1024);        y=randomGenerator.nextInt(700);        hp=100;}}
How to spawn multiple monsters from a single class
java