[Training Video-3] [Groovy in Detail] non-static functions and static functions,initializing log inside Class,objects and object referances

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.