
- 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
Can we implement one interface from another in java?
No, we cannot implement one interface from another you can just extend it using the extends keyword as −
interface ArithmeticCalculations{ public abstract int addition(int a, int b); public abstract int subtraction(int a, int b); } interface MathCalculations implements ArithmeticCalculations{ public abstract double squareRoot(int a); public abstract double powerOf(int a, int b); }
Still, if you try to implement one interface from another using the implements keyword. The compiler does not recognize the implements keyword after the name of the interface and throws a compile time error saying “'{' expected”.
Example
In the following Java program, we have two interfaces namely, ArithmeticCalculations and MathCalculations and, we are trying to implement on interface from the other.
interface ArithmeticCalculations{ public abstract int addition(int a, int b); public abstract int subtraction(int a, int b); } interface MathCalculations implements ArithmeticCalculations{ public abstract double squareRoot(int a); public abstract double powerOf(int a, int b); }
Compile time error
On compiling, the above program generates the following compile time error −
Output
MathCalculations.java:8: error: '{' expected interface MathCalculations implements ArithmeticCalculations{ ^ 1 error
If you compile the same program using eclipse it gives you a compile time error suggesting that “extends keyword is expected instead of implements”.
- Related Questions & Answers
- Can we declare an interface with in another interface in java?
- How can we copy one array from another in Java
- Why an interface cannot implement another interface in Java?
- How can we implement the Subscriber interface in Java 9?
- Can we override only one method while implementing Java interface?
- How we can copy Python modules from one system to another?
- How can we call one constructor from another in the same class in C#?
- Subtract one BigInteger from another BigInteger in Java
- Divide one BigInteger from another BigInteger in Java
- Subtract one BigDecimal from another BigDecimal in Java
- Can we change the access specifier from (public) while implementing methods from interface in Java?
- Can we declare an interface as final in java?
- Can we define constructor inside an interface in java?
- Can we overload methods of an interface in Java?
- How can we implement a JToggleButton in Java?
Advertisements