I have the following objects in the Game class how do I call these objects in class Main
?
team1=new Team(t1, t2, t3);
team2=new Team(e1, e2, e3);
I have the following objects in the Game class how do I call these objects in class Main
?
team1=new Team(t1, t2, t3);
team2=new Team(e1, e2, e3);
There are several ways.
One of them is to use a constructor in its Main
class:
public class Game {
public static void main(String[] args) {
Main main = new Main(new Team(), new Team());
}
}
public class Main {
Team teamUm;
Team teamDois;
public Main(Team teamUm, Team teamDois) {
this.teamUm = teamUm;
this.teamDois = teamDois;
}
}
Another way is by set methods, invoked within Game
:
public class Game {
public static void main(String[] args) {
Main main = new Main();
main.setTeamUm(new Team());
main.setTeamDois(new Team());
}
}
public class Main {
Team teamUm;
Team teamDois;
public void setTeamUm(Team teamUm) {
this.teamUm = teamUm;
}
public void setTeamDois(Team teamDois) {
this.teamDois = teamDois;
}
}
I hope it helps!