/*
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. Jinja2学习笔记暨官方文档的翻译

    http://blog.csdn.net/lgg201/article/details/4647471 呵呵, 刚刚看完Python模板引擎Jinja2的文档, 感觉很好, 觉得动态语言真是很好.  ...

  2. Prince and Princess

    hdu4685:http://acm.hdu.edu.cn/showproblem.php?pid=4685 题意:有n个王子和m个公主,每个王子都会喜欢若干个公主,也就是王子只跟自己喜欢的公主结婚公 ...

  3. Reverse Linked List 递归非递归实现

    单链表反转--递归非递归实现 Java接口: ListNode reverseList(ListNode head) 非递归的实现 有2种,参考 头结点插入法 就地反转 递归的实现 1) Divide ...

  4. 2.5.1 使用alertDialog

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout ...

  5. Java 语言中 Enum 类型的使用介绍

    Enum 类型的介绍 枚举类型(Enumerated Type) 很早就出现在编程语言中,它被用来将一组类似的值包含到一种类型当中.而这种枚举类型的名称则会被定义成独一无二的类型描述符,在这一点上和常 ...

  6. dotfuscator使用方法

    dotfuscator如何对.net程序进行混淆保护对于程序代码的保护,网上有很多资料,有的说混淆,有的说加密,我比较支持混淆的方法,这样可以让反编译劳工,头晕一阵子,哈哈开玩笑.对于加密如果不是不得 ...

  7. Best Premium Private Proxy Service | Lime Proxies

    Best Premium Private Proxy Service | Lime Proxies undefined

  8. 深入分析Java的序列化与反序列化

    序列化是一种对象持久化的手段.普遍应用在网络传输.RMI等场景中.本文通过分析ArrayList的序列化来介绍Java序列化的相关内容.主要涉及到以下几个问题: 怎么实现Java的序列化 为什么实现了 ...

  9. assembly的说明

    Assembly SampleAssembly; // Instantiate a target object. Int32 Integer1 = new Int32(); Type Type1; / ...

  10. html,shtml和htm的区别

    SHTML和HTML的区别,如果用一句话来解释就是:SHTML 不是HTML而是一种服务器 API,shtml是服务器动态产成的html. 虽然两者都是超文本格式,但shtml是一种用于SSI技术的文 ...