Explore Courses Blog Tutorials Interview Questions
0 votes
in Java by (3.4k points)
edited by

If class B and class C extend class A and I have an object of type B or C, how can I determine of which type it is an instance?

1 Answer

0 votes
by (46k points)

Simply, use this syntax to determine an object's class:

if (obj instanceof C) {

//your code


Click here to learn more about Object.getClass()

Related questions

0 votes
1 answer
asked Oct 17, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

29.3k questions

30.6k answers


104k users

Browse Categories