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

最新文章

  1. clr 元数据
  2. 猫哥网络编程系列:详解 BAT 面试题
  3. Sprint评分表
  4. 使用opencv设置图像的格式以及帧率
  5. Java学习笔记之:Java JDBC
  6. js混淆工具
  7. 李洪强iOS开发之【零基础学习iOS开发】【01-前言】02-准备
  8. 《Differential Equations with Boundary-Value Problems》-chaper2-一阶线性方程
  9.  D - 粉碎叛乱F - 其他起义
  10. Django - 模型表单(创建、更新、删除)
  11. 【转】iOS开发路线简述
  12. [mysql]ERROR 1364 (HY000): Field 'ssl_cipher' doesn't have a default value 解决方法
  13. iOS下WebRTC音视频通话(三)-音视频通话
  14. vue相关操作命令
  15. Redis安装完后redis-cli无法使用(redis-cli: command not found)已使用
  16. gensim_主题提取
  17. Python-WSGI协议如何实现?
  18. 使用pidstat监控资源使用
  19. c++ 判断容器A是否是容器B的子集,如果是,返回true(includes)
  20. 【转】C#中continue、break和return用法

热门文章

  1. C++使用回溯法实现N皇后问题的求解
  2. bzoj4764: 弹飞大爷
  3. 1103 Integer Factorization
  4. 为什么我tracert经过H3C设备的时候,老是*号,不回包
  5. 【POJ】2373 Dividing the Path(单调队列优化dp)
  6. 【洛谷】P1388 算式(dp)
  7. IBM AIX创建lv
  8. Storm概念理解
  9. 使用CXF发布和调用webservice之HelloWorld入门
  10. 22_java之File对象