美文网首页
内部类2

内部类2

作者: 哈迪斯Java | 来源:发表于2021-09-25 20:28 被阅读0次

    package oop.Demon10;

    public class Test {
    public static void main(String[] args) {
    //没有面子初始化类,不用将实例保存到变量中
    new Apple().eat();

        UserService userService = new UserService() {
            public void hello(){
                
            }
    
        };
    }
    

    }
    class Apple{
    public void eat(){
    System.out.println("1");
    }
    }

    interface UserService{
    void hello();

    }

    相关文章

      网友评论

          本文标题:内部类2

          本文链接:https://www.haomeiwen.com/subject/ymxfnltx.html