标签:
Bank.log = log Bank b1 = new Bank() b1.name = "BOA" b1.minbalance = 100 b1.city="London" Bank b2 = new Bank() b2.name = "HSBC" b2.minbalance = 100 b2.city="LA" Bank b3 = new Bank("A",100,"X") log.info b3.name Bank b4 = new Bank("B",1200,"X1") Bank b5 = new Bank("C",1300,"X2") log.info b5.minbalance class Bank{ def static log def name def minbalance def city public Bank(){ // no return type, same name with class name log.info "inside constructor" } // public Bank(bankName,bankMinBal,bankCity){ // name = bankName // minbalance = bankMinBal // city = bankCity // } public Bank(name,minbalance,city){ this.name = name this.minbalance = minbalance this.city = city } }
Run result:
Tue Oct 06 19:51:29 CST 2015:INFO:inside constructor Tue Oct 06 19:51:29 CST 2015:INFO:inside constructor Tue Oct 06 19:51:29 CST 2015:INFO:A Tue Oct 06 19:51:29 CST 2015:INFO:1300
[Training Video - 4] [Groovy] Constructors in groovy, this keyword
标签:
原文地址:http://www.cnblogs.com/MasterMonkInTemple/p/4857614.html