第1个回答 2008-12-19
狗================= 是一个类
斑点狗,吉娃娃,哈士奇,拉布拉多===== 是狗类里的对象
狗叫==== 所有的狗都能叫
吉娃娃的叫声==== 只有吉娃娃才能发出吉娃娃的叫声。
狗叫声就是全局的 因为狗都会叫。
而吉娃娃的叫声是局部的 因为只有吉娃娃能发出他特有的叫声。。
第2个回答 2008-12-18
恩,答的不错。
说简单点:全局变量在整个类里都可以引用到的; 局部变量只在程序的一小部分用到的。比如:
for(int i=0; i<10; i++){//.....}
public void test(){
int a=0;
//..........
}
第3个回答 2013-08-16
java中没有全局变量,只有局部变量和成员变量,所谓全局变量是局部变量俗称这种理论完全是在忽悠小白
第4个回答 2008-12-19
Java has 3 variables: static, instance and local variables.
public class Varaibles {
public static final String s1 = "hi 01";
private String s2 = "hi 02";
public void print() {
String s3 = s1 + s2;
System.out.println(s3);
}
}
"s1" is a static variable -- every instance of the class has reference to this variable, ie, it's shared by all the instances of the class Variable.
"s2" is a instance variable -- each instance of the class has its own copy of this variable.
"s3" is a local variable -- it only exists within the block it's declared. in this example, in method print().