Bank.log = Logbank B1 = new Bank () B1.name = "BOA" b1.minbalance = 100b1.city= "London" Bank b2 = new Bank () B2.name = "HSBC" B2 . minbalance = 100b2.city= "LA" Bank B3 = new Bank ("A", "X") log.info b3.namebank b4 = new Bank ("B", "Max", "X1") Bank B5 = new Bank ("C", 1300, "X2") log.info b5.minbalanceclass bank{def static logdef namedef minbalancedef Citypublic Bank () { // No return type, same name with class Namelog.info "inside Constructor"}//public Bank (bankname,bankminbal,bankcity) {// Name = Bankname//minbalance = Bankminbal//city = Bankcity//}public Bank (name,minbalance,city) {this.name = namethis.minbalance = Minbalancethis.city = City}}
Run Result:
Tue Oct 19:51:29 CST 2015:info:inside constructortue Oct 19:51:29 CST 2015:info:inside constructortue Oct 06 19:51:2 9 CST 2015:info:atue Oct 19:51:29 CST 2015:info:1300
[Training Video-4] [Groovy] Constructors in groovy, this keyword