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

  • 相关阅读:
    SQL Server 2005 全文搜索包括改进和更新的干扰词文件FROM MS KB
    服务器内存选项From MS
    跳过事务复制中的错误
    WP7基础补充
    TaoBaoAPI简介3
    登录功能代码
    TaoBaoApI简介1
    TaoBaoAPI简介2
    WP7基础学习第十三讲
    WP7基础学习第十四讲
  • 原文地址:https://www.cnblogs.com/MasterMonkInTemple/p/4857445.html
Copyright © 2011-2022 走看看