log.info "starting"

// we use class to create  objects of a class
Planet p1 = new Planet()
Planet p2 = new Planet() //Planet.name = "Pluto" illegal
Planet.shape = "Circle" // static variable
Planet.log = log p1.name = "earth" // non static variable
p2.name = "jupiter" p1.printName() // non static has to be called with reference
Planet.revolve() // static can be called with class class Planet{
// variables and functions
def name // non static variable
def static shape // static variable
def static log public void printName(){ // non static function
log.info ("Name of planet is $name. Shape is $shape")
xyz() // non static can access static
} public static void revolve(){ // static function
//log.info (name) // error, static cannot access non static
xyz() // call one function from another function
log.info ("Planet revolving. Shape is $shape")
} public static void xyz(){
log.info "inside xyz"
}
}

Test Result:

Tue Oct 06 18:30:29 CST 2015:INFO:starting
Tue Oct 06 18:30:29 CST 2015:INFO:Name of planet is earth. Shape is Circle
Tue Oct 06 18:30:29 CST 2015:INFO:inside xyz
Tue Oct 06 18:30:29 CST 2015:INFO:inside xyz
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. C++直接初始化和复制初始化1

    这篇文章主要介绍了C++直接初始化与复制初始化的区别深入解析,是很多C++初学者需要深入了解的重要概念,需要的朋友可以参考下   C++中直接初始化与复制初始化是很多初学者容易混淆的概念,本文就以实例 ...

  2. 数据结构与算法JavaScript描述——栈

    栈就是和列表类似的一种数据结构,它可用来解决计算机世界里的很多问题. 栈是一种高效的数据结构,因为数据只能在栈顶添加或删除,所以这样的操作很快,而且容易实现. 栈的使用遍布程序语言实现的方方面面,从表 ...

  3. java 重写 与 重载 用法

    图例: 重写: 其实就是获取其他类 和自己类相同的方法名 来使用 重载: 其实就是创建多个相同的方法名,里面装载不同的参数 重写例子: Super关键字 重载的例子:

  4. postman请求ajax失败的解决方法

    第一步,把要提交的数据放到Body里 第二步:去掉请求头的Content-Length字段

  5. PAT甲级 1002 A+B for Polynomials (25)(25 分)

    1002 A+B for Polynomials (25)(25 分) This time, you are supposed to find A+B where A and B are two po ...

  6. Java-Runoob:Java StringBuffer 类

    ylbtech-Java-Runoob:Java StringBuffer 类 1.返回顶部 1. Java StringBuffer 和 StringBuilder 类 当对字符串进行修改的时候,需 ...

  7. Go - 指针简介 与 ++/--运算符以及控制语句

    指针 Go 语言中,对于指针有一些特殊约束: 1. 不在支持 “->” 符号,所有的指针使用“.” 来操作指针对象的成员变量 2. 指针的默认值为 “nil” ++ 与 -- 作为语句而非表达式 ...

  8. buffer cache 深度解析

    本文首先详细介绍了oracle中buffer cache的概念以及所包含的内存结构.然后结合各个后台进程(包括DBWRn.CKPT.LGWR等)深入介绍了oracle对于buffer cache的管理 ...

  9. poj 3790 Recursively Palindromic Partitions

    /*摘抄自博客:Recursively Palindromic Partitions Time Limit: 1000MS Memory Limit: 65536K Total Submissions ...

  10. C#Remoting

    C# Remoting   细细品味C#——.Net Remoting专题 http://www.cnblogs.com/xia520pi/archive/2011/11/02/2233371.htm ...