Java_方法的调用②及案例

语法格式:

    方法名称([参数列表]);  //注意:只能调用本类的方法

案例:

 1   class Method01{
 2 
 3     public static void print(){
 4         for(int i = 1; i <= 5;i++){
 5             System.out.println("第"+ i +"遍HelloWorld!");
 6         }
 7     }
 8     public static void main(String[ ]args){
 9         /*System.out.println("OK");
10         //调用Method01种的print方法,语法格式:类名.方法名称([参数列表]);
11         Method01.print();
12         System.out.println("yes");
13         Method01.print();        */
14         // ↓当调用本类中的方法时,则也可以编写为:方法名称([参数列表])
15         print();
16     }
17   }
18 class Method02{
19     public static void main(String[ ]args){
20         //调用Method01类中的方法
21         //Method01.print();
22         print();    //出现编译错误
23     }
24 }
原文地址:https://www.cnblogs.com/penphy/p/10746157.html