回顾方法的定义

概述

方法的定义

  • 修饰符

  • 返回类型

  • break:跳出switch,结束循环 和return的区别

  • 方法名:注意规范就OK 见名知意

  • 参数列表:(参数类型,参数名) ...

  • 异常抛出:疑问,后面讲解

代码

//Java-零基础学习/src/oop/demo01/Demo01
package oop;

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 hello() {
       return;
  }

   public int max(int a, int b) {
       return a > b ? a : b;//三元运算符!
  }

   //数组下表越界:Arrayindexoutofbounds
   public void readFile(String file) throws IOException {
       
  }
}
 
posted @ 2024-01-13 22:06  poiuyjoey  阅读(4)  评论(0编辑  收藏  举报