Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
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

Browse Categories

...