标签:
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