Using Interface variables

后端 未结 12 1119
广开言路
广开言路 2020-11-28 05:01

I\'m still trying to get a better understanding of Interfaces. I know about what they are and how to implement them in classes.

What I don\'t understand is when you

12条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-28 05:52

    No, it is not possible. Designers did not provide a way. Of course, it is of common sense also. Because interface contains only abstract methods and as abstract methods do not have a body (of implementation code), we cannot create an object..

    Suppose even if it is permitted, what is the use. Calling the abstract method with object does not yield any purpose as no output. No functionality to abstract methods. Then, what is the use of interfaces in Java design and coding. They can be used as prototypes from which you can develop new classes easily. They work like templates for other classes that implement interface just like a blue print to construct a building.

提交回复
热议问题