方法的回顾

方法的回顾
import java.io.IOException;

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

    }
    //return 结束方法,返回一个结果,方法中后续无法再执行任何语句
    public String sayHello(){
        return "hello,world";
    }
    public void helle(){

    }
    public int max(int a,int b){
        return a>b ? a : b; //三元运算符
    }
    // 抛出异常的方法构造
    public void readFile(String file) throws IOException{

    }

}
public class Demo02 {
    public static void main(String[] args) {
        //静态方法调用
        Student.say01();
        // 非静态方法调用 需要实例化 new
        Student student = new Student();
        student.say02();
    }
}
public class Student {
    //静态方法 static
    public static void say01(){
        System.out.println("say01");
    }
    //非静态方法
    public void say02(){
        System.out.println("say02");
    }
}
posted @ 2025-01-21 11:00  EndeavorX  阅读(17)  评论(0)    收藏  举报