Java.lang.Class.isAssignableFrom() Method



The java.lang.Class.isAssignableFrom() determines if the class or interface represented by this Class object is either the same as, or is a superclass or superinterface of, the class or interface represented by the specified Class parameter.


Following is the declaration for java.lang.Class.isAssignableFrom() method

public boolean isAssignableFrom(Class<?> cls)


cls − This is the Class object to be checked.

Return Value

This method returns the boolean value indicating whether objects of the type cls can be assigned to objects of this class.


NullPointerException − if the specified Class parameter is null.


The following example shows the usage of java.lang.Class.isAssignableFrom() method.

package com.tutorialspoint;

import java.lang.*;

public class ClassDemo {

   public static void main(String[] args) {

      try {
         ClassDemo cls = new ClassDemo();
         Class c = cls.getClass();

         // class object associated with BaseClass
         Class bClass = BaseClass.class;

         // checks whether BaseClass is assignable from ClassDemo
         boolean retval = bClass.isAssignableFrom(c);
         System.out.println("Return Value = " + retval);

         // checks whether ClassDemo is assignable from BaseClass
         retval = c.isAssignableFrom(bClass);
         System.out.println("Return Value  = " + retval);
      } catch(Exception e) {

// base class
class BaseClass extends ClassDemo {

    public BaseClass() {
       // no argument constructor

Let us compile and run the above program, this will produce the following result −

Return Value = false
Return Value = true