How do I determine the class of an object?

Asked 2 years ago, Updated 2 years ago, 62 views

If you have classes B and C, both of these inherited A, and when you created an object of B or C, how do you know what class this instantiated?

java inheritance

2022-09-22 14:43

1 Answers

if (obj instanceof C) {
//your code
}

You can do it like this.


2022-09-22 14:43

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.