Simple refactoring in Java (Basics) -


i have these 2 constructors creating bankaccount

    public bankaccount(int accountnumber , double balance) {         // todo auto-generated constructor stub         this.accountnumber = accountnumber;         this.balance = balance;                  system.out.println(this.accountnumber+"    "+this.balance);              }      public bankaccount(int accountnumber) {         // todo auto-generated constructor stub         this.accountnumber = accountnumber;         this.balance = 0;          system.out.println(this.accountnumber+"    "+this.balance);     } 

i want refactor , conform dry (don't repeat yourself) principle.i wrote raises error... please help...

public bankaccount(int accountnumber) {         // todo auto-generated constructor stub         bankaccount(accountnumber,0.0);     }         public bankaccount(int accountnumber , double balance) {         // todo auto-generated constructor stub         this.accountnumber = accountnumber;         this.balance = balance;          system.out.println(this.accountnumber+"    "+this.balance);      } 

use this

public bankaccount(int accountnumber) {     this(accountnumber,0.0); } 

Comments