当前位置:网站首页>Differences between member variables and local variables
Differences between member variables and local variables
2022-06-25 14:30:00 【Hard work boy】
What are the differences between member variables and local variables ?
public class Clothes
{
String id; // Instance variables
private String colorType; // Instance variables
private int size; // Instance variables
private static String depart; // Class variables
final String design="yangzi"; // Constant
}
Instance variables in code 、 Class variables ( Static variables )、 Constants belong to member variables .
Local variables are methods ( function ) Variables temporarily defined in .
- In terms of grammatical form : Member variables belong to classes , Local variables are defined in the method or parameters of the method ; Member variables can be public,private,static Decorated by modifiers such as , Local variables cannot be modified by access control modifiers and static Modified ; however , Both member variables and local variables can be final Modified .
- From the way variables are stored in memory : If the member variable is using the static Embellished , Then this member variable belongs to the class , If not used static modification , This member variable belongs to the instance . And objects exist in heap memory , Local variables exist in stack memory .
- In terms of the lifetime of variables in memory : Member variables are part of an object , It exists as objects are created , Local variables disappear automatically with the method call .
- If a member variable is not given an initial value : The default value of the type is automatically assigned ( One exception is : By final The decorated member variable must also be explicitly assigned ), Local variables are not assigned automatically .
边栏推荐
- API encapsulation of uniapp applet
- JS determines whether two values are equal, and compares any two values, including array objects
- Cool assembly tutorial - concise x86 assembly language tutorial (1)
- Renix Perf: IP网络性能测试工具及测试用例参数详解
- JVM uses tools to analyze classic cases of OOM
- 使用KVM虚拟化部署EVE-NG
- 关于STM32使用LAN8720A插拔网线重连
- 'NVIDIA SMI' is not an internal or external command, nor is it a runnable program or batch file
- Settings the PC must be turned on
- Realization of neural networks with numpy
猜你喜欢

英语中的九大词性与九大时态

"Mobile cloud Cup" computing power network application innovation competition is in hot registration!

Why should programmers be softer?

JVM 用工具分析OOM经典案例

VGA display of de2-115 FPGA development board

shell 变量 入门

Suanli & NFT trading platform f3 The exclusive NFT project of XYZ, hash eagle, will be grandly launched

Share the code technology points and software usage of socket multi client communication

专家建议|8大措施加速你的创新职业规划和成长

Realization of neural networks with numpy
随机推荐
How does hash eagle, the founder of equity NFT, redefine NFT and use equity to enable long-term value?
Renix perf: detailed explanation of IP network performance test tools and test case parameters
腾讯云搭建Socks5多IP代理服务器实现游戏单窗口单IP完美搭建教程附带工具「建议收藏」
分类器与cross entropy loss函数
Shell operator
Hash table, hash conflict
专家建议|8大措施加速你的创新职业规划和成长
112页机器学习-数学基础回顾.pptx
It's not easy to understand the data consistency of the microservice architecture for the first time after six years as a programmer
让PyTorch训练速度更快,你需要掌握这17种方法
通达信股票账户开户安全吗
Why should programmers be softer?
超酷汇编教程-- 简明x86汇编语言教程(1)
Classifier and cross entropy loss function
关于win10 版本kicad 卡死的问题, 版本6.x
Table de hachage, conflit de hachage
None of the MLIR Optimization Passes are enabled (registered 2)解决办法
【HBZ分享】LockSupport的使用
使用sphinx根据py源文件自动生成API文档
【深度学习】多任务学习 多个数据集 数据集漏标