⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 showscope.java

📁 《A first book of java》by Gary J.Bronson 北大出版社
💻 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 + -