There is no constructor for interface in Java?

前端 未结 6 565
深忆病人
深忆病人 2020-12-17 06:48

In Java, if I have an interface:

public interface MyInterface{
}

Then MyInterface implementation is:

class MyC         


        
6条回答
  •  甜味超标
    2020-12-17 07:17

    No it is not possible to declare an instance of myClass since it is an interface.

    Interfaces do not define a constructor, but the class implementing the interface still has a constructor.

    If you intention is to make it impossible for the user to call the constructor of your class, you can always make the constructor private.

提交回复
热议问题