1. log.info "starting"
  2.  
  3. // we use class to create objects of a class
  4. Planet p1 = new Planet()
  5. Planet p2 = new Planet()
  6.  
  7. //Planet.name = "Pluto" illegal
  8. Planet.shape = "Circle" // static variable
  9. Planet.log = log
  10.  
  11. p1.name = "earth" // non static variable
  12. p2.name = "jupiter"
  13.  
  14. p1.printName() // non static has to be called with reference
  15. Planet.revolve() // static can be called with class
  16.  
  17. class Planet{
  18. // variables and functions
  19. def name // non static variable
  20. def static shape // static variable
  21. def static log
  22.  
  23. public void printName(){ // non static function
  24. log.info ("Name of planet is $name. Shape is $shape")
  25. xyz() // non static can access static
  26. }
  27.  
  28. public static void revolve(){ // static function
  29. //log.info (name) // error, static cannot access non static
  30. xyz() // call one function from another function
  31. log.info ("Planet revolving. Shape is $shape")
  32. }
  33.  
  34. public static void xyz(){
  35. log.info "inside xyz"
  36. }
  37. }

Test Result:

  1. Tue Oct 06 18:30:29 CST 2015:INFO:starting
  2. Tue Oct 06 18:30:29 CST 2015:INFO:Name of planet is earth. Shape is Circle
  3. Tue Oct 06 18:30:29 CST 2015:INFO:inside xyz
  4. Tue Oct 06 18:30:29 CST 2015:INFO:inside xyz
  5. Tue Oct 06 18:30:29 CST 2015:INFO:Planet revolving. Shape is Circle

 Note :

Static cannot access non static

[Training Video - 3] [Groovy in Detail] Non-static and Static functions, initializing log inside class的更多相关文章

  1. [Training Video - 3] [Groovy in Detail] Non-static and Static variables, objects and object referances

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

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

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

  3. [Training Video - 4] [Groovy] Function in detail

    Employee.log=log Employee e1 = new Employee() Employee e2 = new Employee() e1.name = "A" e ...

  4. [Training Video - 4] [Groovy] Optional parameter in groovy

    Employee.log=log Employee e1 = new Employee() log.info e1.add(1,2,3,4) // optional parameters in gro ...

  5. [Training Video - 2] [Groovy Introduction]

    Building test suites, Test cases and Test steps in SOAP UI Levels : test step level test case level ...

  6. [Training Video - 4] [Groovy] Constructors in groovy, this keyword

    Bank.log = log Bank b1 = new Bank() b1.name = "BOA" b1.minbalance = 100 b1.city="Lond ...

  7. [Training Video - 5] [Groovy Script Test Step - Collections, Exceptions] Exception Handling in groovy

    def x = new String[3] x[0] = "A" x[1] = "B" x[2] = "C" log.info"X ...

  8. [Training Video - 5] [Groovy Script Test Step - Collections, Exceptions] HashSet and Hashtable

    Hashset: HashSet set = new HashSet() set.add("India") set.add("USA") set.add(&qu ...

  9. [Training Video - 5] [Groovy Script Test Step - Collections, Exceptions] Array and ArrayList

    Array: def x = new String[5] x[0] = "India" x[1] = "USA" x[2] = "Korea" ...

随机推荐

  1. elasticsearch 5.0 获取 TransportClient 操作客户端java API

    本文转载自:http://blog.csdn.net/likui1314159/article/details/53233881 elasticsearch 5.0 获取 TransportClien ...

  2. python is 和 == 的区别

    一.is 和 == 的区别 == 比较 比较的俩边的值 is 比较 比较的是内存地址 id() 二.小数据池 数字小数据池的范围 -5 ~ 256 字符串中如果有特殊字符他们的内存地址就不一样 字符串 ...

  3. android 手机UDP 接受不到数据

    一.有的手机不能直接接收UDP包,可能是手机厂商在定制Rom的时候把这个功能给关掉了. 1.可先在oncreate()方法里面实例化一个WifiManager.MulticastLock 对象lock ...

  4. 设置VS以管理员身份运行

    以vs2013为例 vs右键属性 ----- ​ 找到目标位置如下 "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\ ...

  5. JNI的一个简单实例

    本例子使用的操作系统MacOS, 64位JVM. JNI编写的几个步骤如下: 编写Java代码,并注明native方法: public class HelloJni { public native v ...

  6. Java测试用例简介

    最近需要向组内其他成员普及一下关于Java测试用例的相关知识,特在此进行一下简单的学习和总结. JUnit简介 JUnit是一个开源的Java单元测试框架,JUnit4对原有的JUnit框架进行了大幅 ...

  7. Linux系统命令与脚本开发

    系统命令 # cat EFO cat >> file << EOF neirong EOF # 清空 >file 清空文件 [root@Poppy conf]# sed ...

  8. 关于select的一个死循环

    #include <stdio.h> #include <sys/types.h> #include <unistd.h> #include <sys/sel ...

  9. 【HDU】2222 Keywords Search(AC自动机)

    题目 传送门:QWQ 分析 $ AC $自动机模板,黈力的码风真的棒极了,这是我抄他的. 还有 题号不错 代码 #include <cstdio> #include <cstring ...

  10. ProducerConsumerQueue

    folly/ProducerConsumerQueue.h The folly::ProducerConsumerQueue class is a one-producer one-consumer ...