匿名对象的三种使用方式

52 阅读1分钟
package com.wxt01.nimingduixiang01;

public class demo {
    public static void main(String[] args) {
//        1、直接调用方法
        new student().show();
//        2、作为方法的参数传递
        test(new student());
//        3、作为返回值返回
        getStudent().show();
    }

    public static void test(student s) {
        s.show();
    }
    public static student getStudent(){
        return new student();
    }
}

class student {
    public void show() {
        System.out.println("student匿名方法类中的show方法执行了");
    }
}