/*
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. Milk Patterns

    poj3261:http://poj.org/problem?id=3261 题意:给定一个字符串,求至少出现k 次的最长重复子串,这k 个子串可以重叠. 题解:还是用后缀数组,求H和后缀数组,然后二 ...

  2. jsp页面传参到action出现乱码

    jsp页面以连接方式传参到后台action时( <a href="http://localhost:8080/SocialBook/pages/bookdetail?book.id=& ...

  3. jQuery动态五星评分

    效果 css .star ul, .star li { list-style: none; } .star { position: relative; width: 600px; height: 24 ...

  4. bzoj3437

    练一下斜率优化 ..] of int64; q,a,b:..] of longint; i,n,h,t,j:longint; function g(j,k:longint):double; var a ...

  5. HDU 5924 Mr. Frog’s Problem 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)

    Mr. Frog's Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  6. page-object使用(2)---elements

    elements就是html元素下所有的标签.用page-object你可以找到并定位html页面下绝大多数的元素,这个文章列出了可定位的这些元素,生成的方法,和依据什么关键字来找到这些元素. BUT ...

  7. RTP, RTCP, RTSP 协议介绍

    流媒体是边下载边播放的方式, 是视频会议.IP电话等应用场合的技术基础.           为什么TCP/IP协议就不能满足多媒体通信的要求呢?因为TCP有以下4个特点:1.TCP重传机制2.TCP ...

  8. poj 1696 Space Ant 极角排序

    #include<cstdio> #include<cstring> #include<cmath> #include<iostream> #inclu ...

  9. hdoj 3746 Cyclic Nacklace【KMP求在结尾加上多少个字符可以使字符串至少有两次循环】

    Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  10. 查看mysql数据库及表编码格式

    1.查看数据库编码格式 mysql> show variables like 'character_set_database'; 2.查看数据表的编码格式 mysql> show crea ...