ADVERTISEMENT
ADVERTISEMENT

Java program to get the list of implemented interfaces in a class

Java example to get the list of implemented interfaces in a class.
Submitted by Nidhi, on May 06, 2022

Problem Solution:

In this program, we will get the list of implemented interfaces in a class using the getInterfaces() method and print the result.

Program/Source Code:

The source code to get the list of implemented interfaces in a class is given below. The given program is compiled and executed successfully.

// Java program to get the list of implemented interfaces 
// in a class

interface inf1 {}

interface inf2 {}

class Sample implements inf1, inf2 {}

public class Main {
  public static void main(String[] args) throws ClassNotFoundException {
    Class cls = Class.forName("Sample");
    Class cInf[] = cls.getInterfaces();

    System.out.println("Interfaces implemented by Sample class: ");
    for (Class inf: cInf)
      System.out.println(inf);
  }
}

Output:

Interfaces implemented by Sample class: 
interface inf1
interface inf2

Explanation:

In the above program, we created a public class Main that contains a main() method. The main() method is the entry point for the program. Here, we created two interfaces inf1, inf2 and implemented them into the Sample class.

In the main() method, we got the list of implemented interfaces in the Sample class using the getInterfaces() method and printed them.

Java Class and Object Programs »


ADVERTISEMENT


ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.