当前位置:网站首页>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 .
边栏推荐
- Discriminative v.s.Generative
- Stream竟然还有应用进阶学习?作为程序员的你知道吗
- Thymeleaf Usage Summary
- Is qiniu regular? Is it safe to open a stock account?
- Which is better and safer, GF easy gold rush or flush
- Kubernetes 理解kubectl/调试
- 成员变量与局部变量的区别
- JS determines whether two values are equal, and compares any two values, including array objects
- Basic usage of markdown (plain text and grammar)
- Deconstruction assignment of variables
猜你喜欢
随机推荐
JS component
JVM 用工具分析OOM经典案例
多台云服务器的 Kubernetes 集群搭建
【世界历史】第二集——文明的曙光
JGG | 河北大学杜会龙组综述植物泛基因组学研究
分享自己平時使用的socket多客戶端通信的代碼技術點和軟件使用
Deeply understand the mathematics behind deep neural networks (mysteries of neural networks Part I)
sigmoid函数sigmoid求导
两种方法实现pycharm中代码回滚到指定版本(附带截图展示)
广发易淘金和同花顺哪个更好,更安全一些
Is qiniu regular? Is it safe to open a stock account?
Shell string variable
Discriminative v.s.Generative
一次性总结:64个数据分析常用术语!
API encapsulation of uniapp applet
买基金在哪里开户安全?求指导
None of the MLIR optimization passes are enabled (registered 2) solutions
让PyTorch训练速度更快,你需要掌握这17种方法
golang项目依赖管理工具go vendor,go mod
VGA display of de2-115 FPGA development board




![[untitled]](/img/7f/e2c9fbfb5eb6e7fcc6e23a46540933.jpg)




