The difference between a local variable and a member variable
package com.itheima_04;
/*
* 成员变量和局部变量的区别:
* A:在类中的位置不同
* 成员变量:类中,方法外
* 局部变量:方法中或者方法声明上(形式参数)
* B:在内存中的位置不同
* 成员变量:堆内存
* 局部变量:栈内存
* C:生命周期不同
* 成员变量:随着对象的创建而存在,随着对象的消失而消失
* 局部变量:随着方法的调用而存在,随着方法的调用完毕而消失
* D:初始化值的问题
* 成员变量:有默认值
* 局部变量:没有默认值。必须先定义,赋值,最后使用
*/
public class Variable {
int x; public void show() {
int y = 0; System.out.println(x);
System.out.println(y);
}
}
因为在类中的位置不同->在内存中的位置不同->生命周期不同。这都是有规律可循的。
The difference between a local variable and a member variable的更多相关文章
- 【RF库测试】Variable Should not Exist & variable should exist
Variable Should not Exist variable should exist
- [C++] static member variable and static const member variable
static member variable[可读可写] 可以通过指针间接修改变量的值 static const member variable[只读] 压根就不可以修改变量的值,会报错
- What are the differences between a pointer variable and a reference variable in C++?
Question: I know references are syntactic sugar, so code is easier to read and write. But what are t ...
- 【TensorFlow】TensorFlow获取Variable值,将Variable保存为list数据
Variable类型对象不能直接输出,因为当前对象只是一个定义. 获取Variable中的浮点数需要从数据流图获取: initial = tf.truncated_normal([3,3], stdd ...
- Variable|quantitative variables|continuous variable|discrete variable|qualitative variables| observation|data set
2.1Variables and Data Variable:某物或某人的某一特征和其他个体不同. quantitative variables:定量变量either discrete (可以被数)o ...
- QIBO CMS SQL Injection Via Variable Uninitialization In \member\special.php
Catalog . 漏洞描述 . 漏洞触发条件 . 漏洞影响范围 . 漏洞代码分析 . 防御方法 . 攻防思考 1. 漏洞描述 该漏洞存在于/member/special.php文件下,由于未对变量进 ...
- 【转】Multithreaded Python Tutorial with the “Threadworms” Demo
The code for this tutorial can be downloaded here: threadworms.py or from GitHub. This code works wi ...
- Java相关英语单词
day1 Java概述 掌握 .JDK abbr. Java开发工具包(Java Developer's Kit) (abbr.缩写) .JRE abbr. Java运行环境(Java Runtime ...
- MySQL: @variable vs. variable. Whats the difference?
MySQL: @variable vs. variable. Whats the difference? up vote351down votefavorite 121 In another qu ...
随机推荐
- [性能测试]:关于消费类ISO8583协议脚本的开发
一,要发送的报文,转化成16进制的,报文如下 "\x01\x52"//报文长度338 "\x60\x00\x24\x00\x00"//TPDU "\x ...
- Bluetooth Lowe Energy
BTL---------- // Wikipedia --------The first review paper to read when you counterred a new filed . ...
- java无符号Byte
1.无符号byte, 实现了将byte(-128~127) 转换为 (0~255) class UnsignedByte { private short value; private byte raw ...
- [转] flume使用(六):后台启动及日志查看
[From] https://blog.csdn.net/maoyuanming0806/article/details/80807087 处理的问题flume 普通方式启动会有自己自动停掉的问题,这 ...
- [转] linux alias 编写 函数 脚本
[From] https://blog.csdn.net/csdnmonkey/article/details/53286314 案例 alias ttt='ttt(){ echo $1 ; };tt ...
- 认识python正则模块re
python正则模块re python中re中内置匹配.搜索.替换方法见博客---python附录-re.py模块源码(含re官方文档链接) 正则的应用是处理一些字符串,phthon的博文python ...
- Spring Boot中自动执行sql脚本
说明:所有的代码基于SpringBoot 2.0.3版本 背景 在应用程序启动后,可以自动执行建库.建表等SQL脚本.下文中以要自动化执行people.sql脚本为例说明,脚本在SpringBoot工 ...
- Sublime Text 3新建工程
1. 创建工程 Project > Add Folder to Project 这时在sidebar中将出现刚刚添加的文件目录,如果还需要添加其他目录,则重复这一操作即可. 2. 保存工程 Pr ...
- rpm: error while loading shared libraries: libgcc_s.so.1: cannot open shared object file: No such file or directory解决办法
不多说,直接上干货! 问题详情 [root@bigdatamaster app]# rpm -qa | grep gcc rpm: error : cannot open shared object ...
- maven上传源码到私服
上传源码 项目中采用了分模块的方式构建,直接将maven-source-plugin写到父pom中,尝试了很多次发现源码一直不能上传到私服中,纠结了很长时间才发现原来多模块项目和普通一个项目的配置是有 ...