In this tutorial, we will discuss about the instanceof keyword in Java programming language
In Java programming language the instanceof is a keyword or operator, which is used to check the type of an object at run time. The instanceof operator helps to compare the instance with type and it return either true or false
Test whether the reference variable on the left is an instance /object of the specified type (class or sub class or interface) on the right
Reference_Variable instanceof class_name/interface_name
Example
Sample s=new Sample; System.out.println(s instanceof Sample);
instanceof using with if
if(object intanceof base){ //statement(s) }
program 1
class My_School{ //class with class name public static void main(String args[]){ //main metod school s=new school();//object for class System.out.println(s instanceof school);//true } }
When the above code is executed, it produces the following results:
True
import keyword in Java
Suggested for you
Using Instance of statement in Java
If statements in Java
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…
Java program to check odd or even using recursion In this tutorial, we discuss a…