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

  • 相关阅读:
    Vue之自定义组件的v-model
    compression-webpack-plugin 开启gzip vue
    vue-i18n ,vue项目中如何实现国际化
    vue 组件的 scrollBehavior 2
    vue-router中scrollBehavior的巧妙用法
    页面刷新(vue)
    服务器配置nginx.conf文件
    mobaxterm配置nginx
    flutter环境搭建
    让GIt忽略SSL证书错误的方法
  • 原文地址:https://www.cnblogs.com/MasterMonkInTemple/p/4857445.html
Copyright © 2011-2022 走看看