Log.info "Starting"//We use class to create objects of a classplanet p1 = new Planet () Planet p2 = new Planet () Planet P3 = new Planet ()//planet.name = "Pluto" illegal planet.shape = "circle" p1.name = "earth"//p1.shape = "Circle" 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.shapeclass planet{//variables and functionsdef name Non static variabledef static shape //Static variable}
Operation Result:
Tue Oct 16:27:27 CST 2015:info:startingtue Oct 16:27:27 CST 2015:info:earth circletue Oct 16:27:27 CST 2015:I Nfo:jupiter circletue Oct 16:27:27 CST 2015:info:mars circletue Oct 16:27:27 CST 2015:info:*************** Tue Oct 16:27:27 CST 2015:info:jupiter circletue Oct 16:27:27 CST 2015:info:jupiter Circletue Oct 16:27:27 CST 2015:info:mars circletue Oct 16:27:27 CST 2015:info:******************************* Tue Oct 16:27:27 CST 2015:info:pluto circletue Oct 16:27:27 CST 2015:info:pluto circletue Oct 06 16:27 : CST 2015:info:mars Circle
[Training Video-3] [Groovy in Detail] Non-static and static variables in groovy