

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 an interface cannot implement another interface in Java?
An interface cannot implement another interface in Java.
- An interface in Java is essentially a special kind of class. Like classes, the interface contains methods and variables. Unlike classes, interfaces are always completely abstract.
- An interface is defined just like a class except for the keyword interface in place of a class, the variables are declared in an interface are static and final and the methods are defined in an interface are public abstract methods.
- An interface can extend any number of interfaces but one interface cannot implement another interface, because if any interface is implemented then its methods must be defined and interface never has the definition of any method.
- If we try to implement an interface with another interface, it will throw a compile-time error in Java.
Example
interface MainInterface { void mainMethod(); } interface SubInterface extends MainInterface { // If we put implements keyword in place of extends, // compiler throws an error. void subMethod(); } class MainClass implements MainInterface { public void mainMethod() { System.out.println("Main Interface Method"); } public void subMethod() { System.out.println("Sub Interface Method"); } } public class Test { public static void main(String args[]) { MainClass main = new MainClass(); main.mainMethod(); main.subMethod(); } }
Output
Main Interface Method Sub Interface Method
- Related Questions & Answers
- Why cannot we specify access modifiers inside an interface in C#?
- Can we declare an interface with in another interface in java?
- Can we implement one interface from another in java?
- How to implement an interface using an anonymous inner class in Java?
- Why java8 introduces default method in an interface?
- How to implement Flow.Publisher interface in Java 9?
- Interface in Java
- Why do we need private methods in an interface in Java 9?
- Java Interface methods
- Can Enum implements an interface in Java?
- Why is javascript called Richer Interface?
- Nested interface in Java
- ConcurrentMap Interface in java
- Externalizable Interface in Java
- Deque interface in Java
Advertisements