Planet.log = Loglog.info "Starting"//We use class to create objects of a classplanet p1 = new Planet () Planet p2 = new Pl Anet () Planet p3 = new Planet ()//planet.name = "Pluto" illegal planet.shape = "Circle" p1.name = "earth"//p1.shape = "circ Le "p2.name =" Jupiter "//p2.shape =" circle "P3.name =" mars "//p3.shape =" Circle "log.info p1.name+" +p1.shapelog.info p2. Name+ "" +p2.shapelog.info p3.name+ "" +P3.SHAPEP1 = P2log.info "*************************************" Log.info p1.name + "" +p1.shapelog.info p2.name+ "" +p2.shapelog.info p3.name+ "" +p3.shapep1.name = "Pluto" Log.info "******************** "Log.info p1.name+" "+p1.shape//plutolog.info p2.name+" "+p2.shape//plutolog.info p3.name+" "+ P3.shapep1.printName ()//non static have to is called with Referenceclass planet{//variables and functionsdef name/ /non static VARIABLEDEF static shape//static variabledef static logpublic void Printname () {//non static FUNCTIONLO G.info ("Name of Planet is"+name) Log.info ("Name of Planet is $name")}public static void Revolve () {//Static Functionlog.info ("Planet Revolving")} }
Test Result:
Tue Oct 17:46:18 CST 2015:info:startingtue Oct 17:46:18 CST 2015:info:earth circletue Oct 17:46:18 CST 2015:I Nfo:jupiter circletue Oct 17:46:18 CST 2015:info:mars circletue Oct 17:46:18 CST 2015:info:*************** Tue Oct 17:46:18 CST 2015:info:jupiter circletue Oct 17:46:18 CST 2015:info:jupiter Circletue Oct 17:46:18 CST 2015:info:mars circletue Oct 17:46:18 CST 2015:info:******************************* Tue Oct 17:46:18 CST 2015:info:pluto circletue Oct 17:46:18 CST 2015:info:pluto circletue Oct 06 17:46 : CST 2015:info:mars circletue Oct 17:46:18 CST 2015:info:name of planet is Plutotue Oct 17:46:18 CST 2015:inf O:name of Planet is Pluto
[Training Video-3] [Groovy in Detail] non-static functions and static functions,initializing log inside Class,objects and object referances