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 ...
随机推荐
- winform MD5加密
byte[] result = Encoding.Default.GetBytes(this.tbPass.Text.Trim()); //tbPass为输入密码的文本框MD5 md5 = ne ...
- redux在componentDidMount中出现的问题 --- state 不变
遇到这样一个问题: 在组件的componentDidMount中,我需要使用到redux中存储的某个状态. 但是有趣的是,当我再render中使用相同的状态时,状态会改变,但是在conponentDi ...
- centos7.x设置nginx开机自启动
设置nginx开机自启动(centos7.x) 第一步:进入到/lib/systemd/system/目录 [root@iz2z init.d]# cd /lib/systemd/system/ 第二 ...
- maven项目debug调试不能够进入源码问题解决
Maven项目在debug调试模式的时候,进入调试模式,但是没有进入源码界面. 上述问题的解决方法如下: 第一步: 第二步: 第三步: 第四步: 第五步: 到这里就解决了:
- Linux下设置Tomcat开机启动
1.进入/etc/rc.d/init.d,新建文件tomcat,并让它成为可执行文件 chmod 755 tomcat. #!/bin/bash # # /etc/rc.d/init.d/tomcat ...
- oracle 如何查看已经创建好的触发器语句-select trigger_body from user_triggers where trigger_name='XXXX';
使用trigge_body查询, select trigger_body from user_triggers where trigger_name='XXXX'; 如下图: SQL> sele ...
- Spring @Transactional踩坑记
@Transactional踩坑记 总述 Spring在1.2引入@Transactional注解, 该注解的引入使得我们可以简单地通过在方法或者类上添加@Transactional注解,实现事务 ...
- ef——存储过程
数据库中存在存储过程GetCategory: ALTER proc [dbo].[GetCategory] @cid int as begin select * from Categories w ...
- 【转】Java Spring AOP详解
一.前言 在以前的项目中,很少去关注spring aop的具体实现与理论,只是简单了解了一下什么是aop具体怎么用,看到了一篇博文写得还不错,就转载来学习一下,博文地址:http://www.cnbl ...
- [javaSE] IO流(递归查找指定文件)
递归方法,实现查找目录中以.java为后缀的文件路径,并存入文本文件中 定义一个静态方法fileToLine(),传入参数:File对象目录,List集合对象(List<File> 这样做 ...