Can I create an object for Interface?

后端 未结 7 909
庸人自扰
庸人自扰 2020-12-14 21:32

Is it possible to create an object for an interface? If yes, how is it done? According to my view the following code says that we can:



        
7条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-14 22:01

    You can create an anonymous inner class:

    Runnable r = new Runnable() {
        @Override
        public void run() {
        }
    };
    

    Therefore you create a new class which implements the given interface.

提交回复
热议问题