Free Data Structures and Algorithms Course









Subscribe below and get all best seller courses for free !!!










OR



Subscribe to all free courses

How to determine Interfaces implemented by a class dynamically using Java Reflection API ?.

Program to demonstrate how to determine Interfaces implemented by a class dynamically using Java Reflection API.

package com.hubberspot.reflection;


// Created two three interfaces just for the demo
// such as Shape, Rotation and Movable
interface Shape
{

}

interface Rotation 
{

}

interface Movable
{

}

// Created a class which implements all those interfaces
class Circle implements Shape , Rotation , Movable 
{

}


public class InterfacesFinding {

 public static void main(String[] args) {

  // Get the instance of Class of the type Circle 
  Class classCircle = Circle.class;

  // class Class defines a method which returns
  // an array of interfaces 
  Class[] interfacesArray = classCircle.getInterfaces();

  System.out.println("Interfaces implemented by Circle class are : ");

  for (int i = 0; i < interfacesArray.length; i++) {

   String interfaceName = interfacesArray[i].getName();

   System.out.println(i + 1 + " " +interfaceName);
  }

 }

}


Output of the program : 


 
 
© 2021 Learn Java by Examples Template by Hubberspot