- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Why are interfaces introduced in Java?n
- An interface is a contract of what the classes can do.
- When a class implements an interface, it can provide implementation to all the abstract methods declared in the interface. An interface defines a set of common behaviors The classes implement the interface agrees to these behaviors and provide their own implementation to the behaviors.
- One of the main usages of an interface is to provide a communication contract between two objects.
- If we know a class implements an interface, then we know that class contains concrete implementations of the methods declared in that interface and we are guaranteed to invoke these methods safely. In other words, two objects can communicate based on the contract defined in the interface, instead of their specific implementation.
- Java does not support multiple inheritances, Multiple inheritances permit us to derive a subclass from more than one direct superclass. This poses a problem if two direct superclasses have conflicting implementations. Java does this by permitting us to implements more than one interfaces.
- Since interfaces contain only abstract methods without actual implementation, no conflict can arise among the multiple interfaces.
- Related Articles
- Why are interfaces introduced in Java?
- Why do we use interfaces in Java?
- What are nested interfaces in Java?
- What are the SAM Interfaces in Java?
- Interfaces in Java
- What are the in-built functional interfaces in Java?
- What are the main features and enhancements introduced in Java 9?
- Callback using Interfaces in Java
- Evolution of interfaces in Java
- Functional Interfaces in Java Programming
- What are the core interfaces of Reactive Streams in Java 9?
- Can interfaces have constructors in Java?
- Java 8 default methods in interfaces
- Java 8 static methods in interfaces
- Interfaces and inheritance in Java Programming
- How to extend Interfaces in Java

Advertisements