in JAVA by
Q:
Explain about instanceof operator in java?

Instanceof operator is used to test the object is of which type.

Syntax : <reference expression> instanceof <destination type>

Instanceof returns true if reference expression is subtype of destination type.

Instanceof returns false if reference expression is null.

Example : public classInstanceOfExample {public static voidmain(String[] args) {Integer a =

newInteger(5);if (a instanceof java.lang.Integer) {

System.out.println(true);

} else {

System.out.println(false);

}

15

}

}

Since a is integer object it returns true.

There will be a compile time check whether reference expression is subtype of destination type. If it is not

a subtype then compile time error will be shown as Incompatible types
React.js
Angular
Ethical Hacking
Agile
AWS
BlockChain
Cassandra
Cloud
Salesforce
Scaled Agile
TOGAF
DevOps
GIT
Jenkins
Jira
Kibana
Linux
NGINX
Ansible
Artificial Intelligence

1 Answer

0 votes
by

Instanceof operator is used to test the object is of which type.

Syntax : <reference expression> instanceof <destination type>

Instanceof returns true if reference expression is subtype of destination type.

Instanceof returns false if reference expression is null.

Example : public classInstanceOfExample {public static voidmain(String[] args) {Integer a =

newInteger(5);if (a instanceof java.lang.Integer) {

System.out.println(true);

Click here to read more about JAVA
Click here to read more about Insurance

Related questions

0 votes
asked Jun 17, 2019 in JAVA by reins.robin
0 votes
asked Jun 17, 2019 in JAVA by reins.robin
0 votes
asked Jun 16, 2019 in JAVA by reins.robin
0 votes
asked Jun 16, 2019 in JAVA by reins.robin
0 votes
asked Jun 16, 2019 in JAVA by reins.robin
...