The class Object

Object a = new manifold();
Object b = new box();
Object c = new circle();

Are all valid statements but what data type are they?

In fact they are all of type Object so when you do something like

a.checkCollision(b, c);

It won’t work because checkCollision is a method inside the mmanifold class and does not exist.

((manifold)a).checkCollision(b, c);

will work because you have cast the variable to the correct class.

The same applies to variable a and c they can only access the methods available in the java.lang.Object class.

3 Likes