方法的定义

  • 修饰符
  • 返回类型
  • break:跳出switch,结束循环和return的区别
  • 方法名:注意规范,见名知意
  • 参数列表:(参数类型,参数名)
  • 异常抛出
package oop.demo01;

import java.io.IOException;

//Demo01类
public class Demo01 {
    //main方法
    public static void main(String[] args) {

    }

    /*
    修饰符 方法值类型  方法名(...){
       //方法体
       return 返回值;
    }
     */

    //return 结束方法,返回一个结果
    public String sayHello(){
        return "Hello,World";
    }
    public void print(){
        return;
    }
    public int max(int a,int b){
        return a > b ? a:b;
    }

    //数组下标越界:Arrayindexout
    public  void readFile(String file)throws IOException{
        
    }
}

 

相关文章:

  • 2022-02-09
  • 2022-02-22
  • 2021-11-01
  • 2021-05-21
  • 2021-11-09
  • 2021-08-30
  • 2022-12-23
  • 2021-07-06
猜你喜欢
  • 2021-11-26
  • 2021-11-12
  • 2022-12-23
  • 2021-10-08
  • 2021-05-21
  • 2021-11-21
  • 2021-09-18
相关资源
相似解决方案