Class isInstance() method in Java with Examples Last Updated : 27 Nov, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The isInstance() method of java.lang.Class class is used to check if the specified object is compatible to be assigned to the instance of this Class. The method returns true if the specified object is non-null and can be cast to the instance of this Class. It returns false otherwise. Syntax: public boolean isInstance(Object object) Parameter: This method accepts object as parameter which is the specified object to checked for compatibility to this Class instance. Return Value: This method returns true if the specified object is non-null and can be cast to the instance of this Class. It returns false otherwise. Below programs demonstrate the isInstance() method. Example 1: Java // Java program to demonstrate isInstance() method public class Test { public static void main(String[] args) throws ClassNotFoundException { // returns the Class object for this class Class myClass = Class.forName("Test"); System.out.println("Class represented by myClass: " + myClass.toString()); // get the Class instance using forName() method Class c = Class.forName("java.lang.String"); System.out.println("Class represented by c: " + c.toString()); // Check if object c is compatible // using isInstance() method System.out.println("Is c compatible: " + myClass.isInstance(c)); } } Output: Class represented by myClass: class Test Class represented by c: class java.lang.String Is c compatible: false Example 2: Java // Java program to demonstrate isInstance() method public class Test { public static void main(String[] args) throws ClassNotFoundException { // returns the Class object for this class Class myClass = Class.forName("Test"); System.out.println("Class represented by myClass: " + myClass.toString()); // get the Class instance using forName() method Class c = Class.forName("Test"); System.out.println("Class represented by c: " + c.toString()); // Check if object c is compatible // using isInstance() method System.out.println("Is c compatible: " + myClass.isInstance(c)); } } Output: Class represented by myClass: class Test Class represented by c: class Test Is c compatible: false Reference: https://docs.oracle.com/javase/9/docs/api/java/lang/Class.html#isInstance-java.lang.Object- Comment More infoAdvertise with us Next Article Class isMemberClass() method in Java with Examples S srinam Follow Improve Article Tags : Java Java-lang package Java-Functions Java.lang.Class Practice Tags : Java Similar Reads Class isInterface() method in Java with Examples The isInterface() method of java.lang.Class class is used to check if this Class is an interface. The method returns true if this Class is an interface. It returns false otherwise. Syntax: public boolean isInterface() Parameter: This method does not accept any parameter. Return Value: This method re 2 min read Class forName() method in Java with Examples The forName() method of java.lang.Class class is used to get the instance of this Class with the specified class name. This class name is specified as the string parameter.Syntax: public static Class<T> forName(String className) throws ClassNotFoundException Parameter: This method accepts the 1 min read Class getSigners() method in Java with Examples The getSigners() method of java.lang.Class class is used to get the signers of this class. The method returns the signers of this class. If this object represents a primitive type or void, then this method returns null. Syntax: public Object[] getSigners() Parameter: This method does not accept any 2 min read Class getInterfaces() method in Java with Examples The getInterfaces() method of java.lang.Class class is used to get the interfaces directly implemented by this entity. This entity can be a class or an interface. The method returns an array of interfaces directly implemented by this entity.Syntax: public Class<T>[] getInterfaces() Parameter: 2 min read Class isMemberClass() method in Java with Examples The isMemberClass() method of java.lang.Class class is used to check if this Class is the Member class. The method returns true if this Class is the Member class. It returns false otherwise.Syntax: public boolean isMemberClass() Parameter: This method does not accept any parameter.Return Value: This 2 min read Calendar getInstance() Method in Java with Examples The getInstance() method in Calendar class is used to get a calendar using the current time zone and locale of the system. Syntax: public static Calendar getInstance() Parameters: The method does not take any parameters. Return Value: The method returns the calendar. Below program illustrates the wo 1 min read Like