keyword

The instanceof keyword in Java programming language

The instanceof keyword in Java programming language

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

What is the usage of instaceof keyword

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

There are other Java language keywords that are similar to the this keyword

import keyword in Java

interface keyword in Java

implement keyword in Java

 

Suggested for you

Using Instance of statement in Java

If statements in Java

Access modifier in Java programming
The package keyword in Java programming
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Share
Published by
Karmehavannan

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

1 month ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

1 month ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

9 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

9 months ago