当前位置:网站首页>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 .
边栏推荐
- Output 0 ~ n digits and output multiple times
- Add a string at the input and textarea cursors
- 启牛是正规的吗?股票开户安全吗?
- 重磅!国产 IDE 发布,由阿里研发,完全开源!(高性能+高定制性)
- Is it safe for tongdaxin to open a stock account
- 移除区间(贪心)
- What is the difference between escape, encodeuri and encodeuricomponent?
- Settings the PC must be turned on
- Installation and removal of MySQL under Windows
- 英語中的九大詞性與九大時態
猜你喜欢

Shell built-in commands

Solving error: creating window glfw error: glew initialization error: missing GL version

Application of TSDB in civil aircraft industry

Clinical chemistry | zhangjianzhong / Xu Jian develop single cell precision diagnosis and treatment technology for Helicobacter pylori

Getting started with numpy Library

Classifier and cross entropy loss function

JGG | overview of duhuilong group of Hebei University Research on plant pan genomics

Stream竟然还有应用进阶学习?作为程序员的你知道吗

How to view the Chrome browser plug-in location

Installation and removal of MySQL under Windows
随机推荐
It's not easy to understand the data consistency of the microservice architecture for the first time after six years as a programmer
Mutationobserver listens for DOM changes
Getting started with shell variables
Native JS obtains form data and highlights and beautifies JSON output display
英語中的九大詞性與九大時態
腾讯云搭建Socks5多IP代理服务器实现游戏单窗口单IP完美搭建教程附带工具「建议收藏」
Shell operator
重磅!国产 IDE 发布,由阿里研发,完全开源!(高性能+高定制性)
Is it safe for tongdaxin to open a stock account
【HBZ分享】LockSupport的使用
Asp. Net webform exporting excel using npoi
【深度学习】多标签学习
What is the safest app for stock account opening? Tell me what you know
How to view the Chrome browser plug-in location
Today in history: Netease was founded; The first consumer electronics exhibition was held; The first webcast in the world
完整详细的汇编实验报告
Where is it safe to open an account for buying funds? Ask for guidance
Cool assembly tutorial - concise x86 assembly language tutorial (1)
多台云服务器的 Kubernetes 集群搭建
Discriminative v.s.Generative