Values in Java (or Object Pascal or Smalltalk or Objective-C) all ``know'' what class they are from - functions are provided to test this.
Once a class type is checked, a cast can be used to convert value.
Ball aBall = ...; if (aBall instanceof BlackBall) { BlackBall bball = (BlackBall) aBall; ... }