Sobes.tech
Junior — Middle

Can a specific object be considered an instance of a particular class?

sobes.tech AI

Answer from AI

Yes, in Java, you can check if an object is an instance of a specific class using the instanceof operator. It returns true if the object belongs to the specified class or its subclass.

Example:

if (obj instanceof MyClass) {
    // obj is an instance of MyClass or its subclass
}

This is useful for safe type casting and runtime type checking.