/*
member variable and static variable:
1,invoke ways:
member variable,also called 'instance' variable,which can only be invoked by instance.
static variable,also called 'class' variable,which [can also] invoked by class,and it is recommended that it invoked using 'class' rather than 'instance'.
2,storage places:
instance variable is stored in the 'heap',
whereas, static variable is stored in the static area of the 'method area'.
3,life cycle:
static var exists as the existence of the class, and gone as the disappear of the class.[general] the 'class' exists when the JVM works,and disappear when the JVM stopped.
instance var exists as the existence of the instance,and gone when the instance was released.
4,memory location:
static var located in the static area of the Method Area,whereas,
instance var located in the heap.
*/
package kju.obj; import static kju.print.Printer.*;
public class InstanceVarStaticVar {
public static void main(String[] args) {
println(Person.country); //use the 'static' var by 'class' instead of the instance.
printHr();
Person lily = new Person("lily");
println(lily.getName());
println("set:");
lily.setName("lucy");
println(lily.getName());
println();
}
} class Person {
public static final String country = "cn";
public Person(String name) {
this.name = name;
} public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
} private String name;
}

Member var and Static var.的更多相关文章

  1. js添加var和不加var区别

    var 声明的变量,作用域是当前 function 没有声明的变量,直接赋值的话, 会自动创建变量 但作用域是全局的. //----------------- function doSth() { a ...

  2. get_object_vars($var) vs array($var)

    get_object_vars(\(var) vs array(\)var) test case class Test { public function actionGetObjectVarsVsA ...

  3. javascript 中加’var‘和不加'var'的区别,你真的懂吗?

    没看之前千万别说我是标题党,这个问题真的有好多淫都不懂!!! 大家都看了很多文章,都说避免隐式声明全局变量,就是说声明变量前必须加'var',那加了'var'和不加'var'到底有啥区别呢? 先来看一 ...

  4. Js变量定义——fn里 var与不var的区别

    js运行时内置了一个Global对象. 这个Global对象跟运行环境有关.在浏览器运行环境中.Global就是window对象.在nodejs中.Global对象是global对象. 当你在浏览器环 ...

  5. var a=[]; 和 var a=new Array(); 的区别,为什么前者效率高

    因为 JSON格式的语法是引擎直接解释的.而new Array 则需要调用Array的构造器.还有就是1.当你需要将一个数字转化为字符串时可以这样定义:var s=""+1; 这样 ...

  6. JavaScript中变量声明有var和没var的区别

    JavaScript中变量声明有var和没var的区别 JavaScript中有var和没var的区别 Js中的变量声明的作用域是以函数为单位,所以我们经常见到避免全局变量污染的方法是 (functi ...

  7. javascript中加var和不加var的区别

    Javascript是遵循ECMAScript标准下的一个产物,自然ECMAScript的标准其要遵循. 先来看下var关键字的定义和用法 var 语句用于声明变量. JavaScript 变量的创建 ...

  8. 有var和没有var的本质区别

    我们创建一个变量: var a = 100: 同时,大家也知道,就是不写var关键字也可以创建.在很多教程和说法中,将没有var 的这个名称称之为“全局变量”.如果我在全局直接写一个var abc = ...

  9. 详解变量声明加 var 和不加 var 的区别

    在全局作用域中声明变量加 var 关键字和不加 var ,js 引擎都会将这个变量声明为全局变量,在实际运行时,两种声明方式的变量的行为也是几乎一致的.但是在全局作用域下是否声明一个变量的 时候加va ...

随机推荐

  1. FLASH 存储学习-串行SPI NOR FLASH

    1.1 SST25VF080B简介1.1.1 主要特性 关键点:容量.速度(时钟速度.读写速度).功耗. l 容量:8MBit: l 最高SPI时钟频率:50MHz: l 低功耗模式下电流消耗:5uA ...

  2. JS仿淘宝详情页菜单条智能定位效果

    类似于淘宝详情页菜单条智能定位 对于每个人来说并不陌生!如下截图所示:红色框的那部分! 基本原理: 是用JS侦听滚动事件,当页面的滚动距离(页面滚动的高度)大于或者等于 "对象"( ...

  3. Android笔记:触摸事件的分析与总结----TouchEvent处理机制

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://glblong.blog.51cto.com/3058613/1559320   ...

  4. 【HDOJ】1455 Sticks

    DFS.搜索以棍数为条件循环搜索较好,这样不会超时. #include <stdio.h> #include <string.h> #include <stdlib.h& ...

  5. Tomcat禁止显示目录和文件列表

    Tomcat禁止显示目录和文件列表 打开   tomcat的安装目录/conf/web.xml 文件 <servlet> <servlet-name>default</s ...

  6. .config-20150410

    ## Automatically generated file; DO NOT EDIT.# OpenWrt Configuration#CONFIG_MODULES=yCONFIG_HAVE_DOT ...

  7. [LeetCode#263]Factorial Trailing Zeroes

    Problem: Write a program to check whether a given number is an ugly number. Ugly numbers are positiv ...

  8. ☀【HTML5】Modernizr

    Modernizr 使用Modernizr探测HTML5/CSS3新特性

  9. CentOS下安装gcc和gdb

    我的操作系统是CentOS6.4,安装源里自带了gcc4.4.0和gdb7.0,版本略老遂删除之重新安装. gcc 1.下载源码包,解压 //下载 wget http: //ftp.gnu.org/g ...

  10. msql修改字符

    我申请了一个jsp空间,把数据库传上去,编码如下mysql> show variables like '%char%';+--------------------------+--------- ...