Java - instanceof Operators / Chapter -6 / Operator & Assignments

1.We can apply instanceof operator is only for objects types. instanceof operator checks whether the given objects is related to a particular type or not.

 example:-

 

Thread t =new Thread( );                                           

System.out.println(t instanceof Thread ) ; output is   true

System.out.println(t instanceof Object) ; output is    true

System.out.println(t instanceof Runable) ;output is   true

 

 

2.To use instanceof  operator compulsory there should be a relation between argument type(either parent to child or child to parent or some type) otherwise, we will get the compile-time error saying"inconvertible types".


 example:-

Thread t =new Thread( );

System.out.println(t instanceof String) ;

Compile-Time Error saying"in-convertible types".

                            found : java.lang.Thread

                         required: java.lang.String

 

 

 

 Next:Chapter -7/Operator & Assignments / Bitwise  Operators

Back:Chapter -5/Operator & Assignments / Equality Operators 

Home:

 

No comments:

Post a Comment

Be the first to comment!

Don't just read and walk away, Your Feedback Is Always Appreciated. I will try to reply to your queries as soon as time allows.

Note:
1. If your question is unrelated to this article, please use our Facebook Page.
2. Please always make use of your name in the comment box instead of anonymous so that i can respond to you through your name and don't make use of Names such as "Admin" or "ADMIN" if you want your Comment to be published.

Regards,
JavaByChetan
Back To Home

Flipkart End Of Season Sale






© Copyright 2017 Javabychetan.blogspot.com