I am wondering if I can use for each loop to iterate through the object of a class. for instance, I created an object honda of type car. I append all the state of the car such as model, price, color, etc. to it. I want to print all the instance of the car. I don't want to use the print statement to print each instance . what is the best way to do it? Thanks.
Below is my java code
package classandobjects;
public class MainClass {
    public static void main(String[] args) {
        Classes friend1 = new Classes();
        friend1.name="yusuf";
        friend1.age=27;
        friend1.country="Nigeria";
        friend1.department="EE";
        friend1.gender="male";
        Classes friend2 = new Classes();
        friend1.name="mathew";
        friend1.age=30;
        friend1.country="Nigeria";
        friend1.department="EE";
        friend1.gender="male";
        FavPlayers player = new FavPlayers();
        player.pname="J.Terry";
        player.position="C.Back";
        player.gaols=38;
        player.awards="25-awards";
        FavPlayers player1 = new FavPlayers();
        player1.pname="F.Lampard";
        player.position="Midfield";
        player.gaols=50;
        player.awards="10-awards";
        Car model = new Car();
        model.modelName="Honda Civic";
        model.color="Ash-color";
        model.Doors="4-doors";
        model.price=900000;
        System.out.println("below is my friend information");
        System.out.println(friend1.name);
        System.out.println(friend1.age);
    }
}
 
     
     
    