Class compatibility check (is) in Java
Forums:
class Shape { }
class Square extends Shape { }
class RedSquare extends Square { }
Square square = new Square();
Boolean isShape = square instanceof Shape;
//isShape is True
Boolean isRedSquare = square instanceof RedSquare;
//isRedSquare is False
- Log in to post comments