oop - Java, Object Oriented Programming -


can me followings please: - have gomuku class extend model, , need copy constructor instead of re-initializing everything, call model constructor gomuku class:

//this model constructor         public model ( model other ) {     this.w = other.w;     this.h = other.h;     this.blacksturn = other.blacksturn;     this.gamestarted = other.gamestarted;     this.gameover = other.gameover;     this.blackwon = other.blackwon;     this.whitewon = other.whitewon;       if (other.w <= 0 || other.h <=0) return;     this.board = new piece[other.h][other.w];     this.winningsequence = new arraylist<>();     for(int r=0; r<other.h; r++){         for(int c=0; c<other.w; c++){             this.board[r][c] = piece.none;         }     } }  //this gomuku      public gomoku ( gomoku other ){     //i want call model constructor instead of initializing in here.     //other.winningsequence = new arraylist<>(); } 

assuming have copy constructor in model. need y use model constructor, possible gooko object, because gomoku extends model. please check this example.

 public gomoku ( gomoku other ){    super(other); // initialize model properties    // set other properties, belong gomoku   } 

by invokin super(object) refering model constructor, accepts model argument. because gomoku extends model, can use gomoku object here.

in model class have problem property order. line containing

if (other.w <= 0 || other.h <=0) return; 

can break initializing of winningsequence list, can initalize before declared constructor.

class model{ private list<?> winningsequence = new arrazlis<>();   public model ( model other ) {   // constructor  } }  

or

  public model ( model other ) {       this.winningsequence = new arraylist<>(); // use before if statement   } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -