📄 showscope.java
字号:
public class ShowScope
{
private static int firstnum; // this has class scope
// all variables in this method have block scope
public static void main(String[] args)
{
int secnum; // create a local variable named secnum
firstnum = 10; // store a value into the class variable
secnum = 20; // store a value into the local variable
System.out.println("From main(): firstnum = " + firstnum);
System.out.println("From main(): secnum = " + secnum);
changeValues(); // call the method changeValues
System.out.println("\nFrom main() again: firstnum = " + firstnum);
System.out.println("From main() again: secnum = " + secnum);
}
// all variables declared in this method have block scope
public static void changeValues() // no values are passed to this method
{ // and no value is returned
int secnum; // create a local variable named secnum
secnum = 30; // this only affects this local variable's value
System.out.println("\nFrom changeValues(): firstnum = " + firstnum);
System.out.println("From changeValues(): secnum = " + secnum);
firstnum = 40; // this changes firstnum for both methods
}
} // end of class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -