码迷,mamicode.com
首页 > 其他好文 > 详细

[Training Video - 4] [Groovy] Constructors in groovy, this keyword

时间:2015-10-06 20:43:12      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!