Class.isassignablefrom () is a subclass or interface that is used to determine whether a class Class1 and another class Class2 are the same or another class.
The format is:
Class1.isassignablefrom (CLASS2)
Both the caller and the parameter are java.lang.Class types.
andinstanceofis used to determine whether an object instance is an instance of a class or interface or its subclass sub-interface.
The format is: o instanceof TypeName
The first parameter is the object instance name, and the second parameter is the specific class name or interface name, for example, String,inputstream. Java code package com.bill99.pattern; public class assignabletest { public Assignabletest (string name) { } /** * Determine whether a class is a parent of another class * is print true * no print false */ public static void testisassignedfrom1 () { system.out.println ("String is the parent class of object:" +string.class.isassignablefrom ( Object.class); } /** * determine whether a class is a parent class of another class * is print true * no print false */ public static void testisassignedfrom2 () { system.out.println ("object is a string's parent class:" + Object.class.isAssignableFrom (String.class)); } /** * Determine if a class is the same as another class * Print true * no print false */     PUBLIC STATIC VOID TESTISASSIGNEDFROM3 () { system.out.println ("Object and object are the same:" +object.class.isassignablefrom ( Object.class); } /** * determine if STR is an instance of object class * is print true * no print false */ Public static void testinstanceof1 () { string str = new string (); system.out.print ("Str is an instance of object:"); System.out.println (str instanceof object); } /** * judgment O is an instance of object class * print true * no print false */ public static void testinstanceof2 () { &nbsP; object o = new object (); system.out.print ("O is an instance of object:"); system.out.println (o instanceof object); } public static void main ( String[] args) { testisassignedfrom1 (); testisassignedfrom2 ();       TESTISASSIGNEDFROM3 (); testinstanceof1 (); testinstanceof2 (); } }
Results:
String is the parent class of object: False
object is the parent class of string: True
object is the same as object: True
STR is an instance of object: True
O is an instance of object: True