1 year ago
#71085
Henrik.A
Creating objects inside the Constructor
I am in the process of understanding various keywords. I got stuck with 'new' keyword. My question is that, why is there a need to create objects of the classes inside the Constructor. Would it make anydifference if you just did inside the other methods where you need them? What is the benefits of doing it this way?
public class Game {
private Board board;
private GUI gui;
private Die die;
private ChanceDeck chanceDeck;
private PlayerCollection players;
private Game()
{
this.board = new Board();
this.gui = new GUI(this.board.getGuiFields());
this.die = new Die();
this.chanceDeck = new ChanceDeck();
this.players = new PlayerCollection();
}
}
java
methods
new-operator
keyword
0 Answers
Your Answer