Analysis of the difference between global variables and member variables

Member variables

A member variable is a member variable of a specified dimension that identifies a dimension member.

Introduces values ​​used internally by Analysis Services to identify a dimension member. The MemberKeyColumn property specifies the member variable of the dimension. For example, a number between 1 and 12 can be a member variable corresponding to a month of the year.

Java member variables and method member variables: Variables defined in the variable part of the class body, also known as fields. Let's first look at a member variable of the Clothes class:

Package ch05.sample

;public class Clothes

{

String id; / / instance variable

Private String colorType; / / instance variable private int size; / / instance variable private staTIc String depart; / / class variable final String design = "yangzi"; / / constant }

Instance variables, class variables, and constants in the code belong to member variables, so what is the basis for their differentiation? This is related to the modifier of the variable, that is, the modifiers such as private, staTIc, and final in the above code.

Analysis of the difference between global variables and member variables

Global variable

A global variable is one of the programming terms that stems from the division of variables.

Variables are divided into local and global, and local variables can be called internal variables. Variables created by an object or a function are usually local variables that can only be referenced internally and cannot be referenced by other objects or functions.

Global variables can be created either as an object function or anywhere in the program. Global variables are referenced by all objects or functions of the program. A local variable will be a null value when it is referenced by another object. But global variables don't happen.

Use in object-oriented languages

In modern object-oriented languages ​​such as Java, C++, C#, Ruby, since variables are encapsulated in classes and are invisible to other classes, the concept of global variables has been almost completely abandoned. However, by defining a class as public staTIc, the class member variable is also defined as public staTIc, so that the variable occupies a fixed, unique piece of space in memory to implement the function of the global variable.

Analysis of the difference between global variables and member variables

The difference between member variables and global variables

Global variables: also called member variables, are variables defined in the class; it is valid throughout the class

Global variables can be further divided into: class variables and instance variables

1. Class variable: It is also called static variable. It can be modified by static. It can be called directly with the class name. It can also be called with the object and the same class variable of all objects is shared.

a memory space

2. Instance variables: without static modification it can only be called by the object and the same instance variable of all objects is sharing different memory space

Local variables: those variables defined in the body of the method and the parameters of the method. It is only valid within the method that defines it.

Note: If the name of a local variable in a method is the same as the name of the global variable, the global variable is temporarily invalidated in this method.

Public class Test{

Int a=0; //global variable

Public static void main(String[] args){

Int b =0; / / local variables

}

}

First look at the following two procedures:

Procedure one:

Public class Variable

{

Int i;

Void test()

{

Int j=8;

If(j==i)

System.out.println("equal");

Else

System.out.println ("not equal");

}

Public static void main(String[] args)

{

Variable v=new Variable();

V.test();

}

}

Procedure 2:

Public class Variable

{

Void test()

{

Int i;

Int j=8;

If(j==i)

System.out.println("equal");

Else

System.out.println ("not equal");

}

Public static void main(String[] args)

{

Variable v=new Variable();

V.test();

}

}

-------------------------------------------------- -------------------------------------------------- ------

The first program is normal and will not fail when compiled. The second program will prompt the following error when compiling:

D:\Program\javaest"javac Variable.java

Variable.java:9: The variable i may not have been initialized yet

If(j==i)

^

1 error

The reason for this error is that: member variables have default values, (finally modified and no static must be explicitly assigned), local variables are not automatically assigned

=========================================================== =========

The class body is divided into two parts. The variables defined in the variable definition part are called the member variables of the class, and the parameters of the variables and methods defined in the method body are called local variables.

The difference between member variables and local variables in java

1. Member variables can be modified by public, protect, private, static, etc., and local variables can not be modified by control modifiers and static; both can be defined as final type

2. Member variables are stored in the heap, local variables are stored in the stack

3. Different time exists

4. Member variables have default values, (finally modified and not static must be explicitly assigned), local variables are not automatically assigned

-------------------------------------------------- -------------------------------------------------- ---------

As the name suggests

What is local, inside the method, the inside of the block is local, the execution instruction exits the local, and the local variable is automatically cleared.

For example, in the method, needless to say

In the block

{

Int i=0; //This is a local variable whose scope is in it

}

Who is the member variable and the member of the class? Member of the instance?

Class A{

Int i=0; //member of the instance

Static j=1;//member of the class

}

The difference in static, whether it depends on the instance

-------------------------------------------------- -------------------------------------------------- ------

Member variable: exists as a member of a class and exists directly in the class.

Local variable: exists as a member of a method or block of statements and exists in the parameter list and method definition of the method.

Local variables must be actively initialized by the programmer before use. In contrast, the member variables in the system are given a default initial value by the system. So in the grammar, the member variables of the class can be used directly after definition, and the local variables must be assigned initial values ​​before they can be used.

Member variables of all classes can be referenced by this. Member variables are divided into two types: instance variables and static variables. Static variables are defined using the static keyword

Anti-Jamming RC Arc Extinguisher

Anti-Jamming RC Arc Extinguisher

YZPST-302327PP(4)

Anti-Jamming RC Arc Extinguisher

YANGZHOU POSITIONING TECH CO., LTD. , https://www.cndingweitech.com