zoukankan      html  css  js  c++  java
  • [Training Video

    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

  • 相关阅读:
    idea添加类注释和方法注释
    蓝桥杯ALGO-1,区间k大数查询
    personalblog
    ul+li水平居中的几种方法
    前端ps部分
    帝国cms-tab
    帝国cms判断某一字段是否为空
    帝国cms建站总结-(分页)
    Js获取验证码倒计时
    前端截取字符串:JS截取字符串之substring、substr和slice详解
  • 原文地址:https://www.cnblogs.com/MasterMonkInTemple/p/4857445.html
Copyright © 2011-2022 走看看