第1个回答 推荐于2018-04-04
public class Test {
String str1 = "Hello 1"; //全局变量
public static void main(String[] args) {
Test t = new Test();
t.sayHello(t.str1);
//t.sayHello(str2); //编译无法通过
}
private void sayHello(String str){
String str2 = "Hello 2";//局部变量
System.err.println(str);
}
}本回答被提问者和网友采纳