Is instanceof and getClass similar?
No, they are not the in the sense that the instanceof refers to an operator whereas the getClass refers to a method, usually of the class java.lang.Object class. Take into consideration a scenario where if(o.getClass().getName().equals(“java.lang.Math”)){ } is used, the only check by this method is whether we have passed a classname equal to java.lang,Math, the class java.lang.Math is loaded by the bootsrap classLoader of which is an abstract class. The responsibility of a classLoader is definitely to load classes and all objects of the given classes have references to this classLoader. Returning of the runtime class of object is performed by the getClass method by fetching the instance of java for a type name, which has been qualified fully. The code which we wrote is of no significance as we arent supposed to compare getClass.getName(). This is because if two separate class loaders load the same class, Java Virtual Machine will consider them as separate classes. The only thing it can