- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
List the Interfaces that an Interface Extends in Java
The interfaces that are implemented by an interface that is represented by an object can be determined using the java.lang.Class.getInterfaces() method. This method returns an array of all the interfaces that are implemented by the interface.
A program that demonstrates this is given as follows −
Example
package Test; import java.lang.*; import java.util.*; public class Demo { public static void main(String[] args) { listInterfaces(java.util.List.class); } public static void listInterfaces(Class c) { System.out.println("The interface is: " + c.getName()); Class[] interfaces = c.getInterfaces(); System.out.println("The Interfaces are: " + Arrays.asList(interfaces)); } }
Output
The interface is: java.util.List The Interfaces are: [interface java.util.Collection]
Now let us understand the above program.
The method listInterfaces() is called with java.util.List.class in the method main(). A code snippet which demonstrates this is as follows −
listInterfaces(java.util.List.class);
In the method listInterfaces(), the method getName() is used to print the name of the interface. Then the method getInterfaces() is used to return an array of all the interfaces that are implemented by the interface. Then this array is printed using Arrays.asList(). A code snippet which demonstrates this is as follows −
System.out.println("The interface is: " + c.getName()); Class[] interfaces = c.getInterfaces(); System.out.println("The Interfaces are: " + Arrays.asList(interfaces));
- Related Articles
- Can an interface in Java extend multiple interfaces?
- Can an interface extend multiple interfaces in Java?\n
- List the Interfaces That a Class Implements in Java
- The extends Keyword in Java
- What is list interface in Java?
- Interfaces in Java
- Why an interface cannot implement another interface in Java?
- What are the class implementations of List interface in Java?
- Prove that the interface for a primitive type is an empty array in Java
- How to list all the classes, interfaces, and enums in JShell in Java 9?
- Must we implement all the methods in a class that implements an interface in Java?
- Can we declare an interface with in another interface in java?
- Difference Between extends and implements keywords in Java
- What are the SAM Interfaces in Java?
- Functional Interfaces in Java Programming
