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

[Training Video - 3] [Groovy in Detail] What is a groovy class ?

时间:2015-10-06 16:52:02      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:

log.info "starting"
// we use class to create  objects of a class
Planet p1 = new Planet()
Planet p2 = new Planet()
Planet p3 = new Planet()

p1.name = "earth"
p1.shape = "circle"

p2.name = "jupiter"
p2.shape = "circle"

p3.name = "mars"
p3.shape = "circle"

log.info p1.name+"  "+p1.shape
log.info p2.name+"  "+p2.shape
log.info p3.name+"  "+p3.shape

p1 = p2
log.info "*************************************"
log.info p1.name+"  "+p1.shape
log.info p2.name+"  "+p2.shape
log.info p3.name+"  "+p3.shape

p1.name = "pluto"
log.info "*************************************"
log.info p1.name+"  "+p1.shape    //pluto
log.info p2.name+"  "+p2.shape    //pluto
log.info p3.name+"  "+p3.shape

class Planet{
// variables and functions
	def name
	def shape
}

运行结果

Tue Oct 06 16:22:05 CST 2015:INFO:starting
Tue Oct 06 16:22:05 CST 2015:INFO:earth  circle
Tue Oct 06 16:22:05 CST 2015:INFO:jupiter  circle
Tue Oct 06 16:22:05 CST 2015:INFO:mars  circle
Tue Oct 06 16:22:05 CST 2015:INFO:*************************************
Tue Oct 06 16:22:05 CST 2015:INFO:jupiter  circle
Tue Oct 06 16:22:05 CST 2015:INFO:jupiter  circle
Tue Oct 06 16:22:05 CST 2015:INFO:mars  circle
Tue Oct 06 16:22:05 CST 2015:INFO:*************************************
Tue Oct 06 16:22:05 CST 2015:INFO:pluto  circle
Tue Oct 06 16:22:05 CST 2015:INFO:pluto  circle
Tue Oct 06 16:22:05 CST 2015:INFO:mars  circle

 

[Training Video - 3] [Groovy in Detail] What is a groovy class ?

标签:

原文地址:http://www.cnblogs.com/MasterMonkInTemple/p/4857304.html

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