回顾方法及加深
方法的定义
- 修饰符
- 返回类型
- break和return的区别
break:跳出switch,结束循环
return 结束方法,返回一个结果!
- 方法名:注意规范 见名知意
- 参数列表:(参数类型,参数名)…
- 异常抛出:
代码如下:
package com.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 hello(){
return;
}
//比大小
public int max(int a,int b){
return a>b?a:b;//三元运算符
}
//数组下标越界 ArrayIndexOutOfBounds
//异常抛出
public void readFile(String file) throws IOException{
}
}