7.方法(method)
被调例子,
int add(int x, int y){
 return x+y;
 }
 主调例子,
 for example:
 int result = add(5,3);
大家可以看出来和c语言是一样的。
7.1 Variable Scope(变量范围)
 1)Class(类) scope
 类中所有的方法都可以用
 2)Block(块) scope
 只在他声明的块中有效 or 嵌套的块儿中
 3)Method(方法) scope
 只在他声明的方法中有效
下例中,i是类变量,k 是块儿变量,j是方法变量,
 public class Test{
     static int i = 10;
     public static void main(String[] args){
         int j = 20;
         int r = cube(i);
         System.out.println(r);
         r = cube(j);
         System.out.println(r);
         {   
             int k = 30;
             r = cube(k);
             System.out.println(r);
         }
     //r = cube(k);there is an error here.错误
     }
     static int cube(int n){
         return n*n*n;
     }
 }
更多内容请见原文,原文转载自:https://blog.csdn.net/qq_44639795/article/details/103145051
原文:https://www.cnblogs.com/shituxingzhe1949/p/14236572.html