![]() ![]() ![]() It provides total abstraction means all the methods in an interface are declared with the empty body, and all the fields are public, static and final by default. It can be used to achieve loose coupling.Īn interface is declared by using the interface keyword.By interface, we can support the functionality of multiple inheritance.There are mainly three reasons to use interface. Since Java 9, we can have private methods in an interface. Since Java 8, we can have default and static methods in an interface. It cannot be instantiated just like the abstract class. Java Interface also represents the IS-A relationship. In other words, you can say that interfaces can have abstract methods and variables. It is used to achieve abstraction and multiple inheritance in Java. ![]() There can be only abstract methods in the Java interface, not method body. The interface in Java is a mechanism to achieve abstraction. ![]() It has static constants and abstract methods. Why multiple inheritance is supported in Interface while it is not supported in case of class.Īn interface in Java is a blueprint of a class. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |