instanceof keyword with an example in java

The instanceof keyword is useful to compare an object  of specific class/interface or specific type.

instanceof keyword Possible to know same class object and subclass “is a” type of its super class (inheritance concept) .
instanceof keyword Returns false , if instanceof with  null object.

instanceof keyword It returns true, when checking any class or interface object with Object using instanceof .
instanceof keyword Useful to know the object is an instance of a class that implement a particular interface.

1 Example for instanceof keyword :

2 Example for instanceof keyword :

Execution Result:

Line no 35 not printed , because we are comparing with a null value.

instanceof keyword Try to use instanceof keyword as less as possible,otherwise it should be consider as a bad design.

Related Posts :
How to Connect to Oracle from Liferay portlet ( Java Liferay and Oracle integration )
How to Connect Liferay 7 to PostgreSQL ( Java Liferay portlet and PostgreSQL integration )
How to call C# .Net WCF web service in java SOAP client ( Visual Studio 2013 )
How to call PHP RESTful web service in java client
How to call java SOAP web service in php ( php web service client )
Solution to SSLHandshakeException (skip the certificate for Java and LDAP bind)
Java RESTful web service example in maven using JAX-RS
RESTful web service example in java using JAX-RS
   [will not be published]

^ <