Converting and Casting Reference Types

Java has three kinds of reference type variables: class type, interface type, and array type. A variable of type Object can hold a reference to any of these three types because Object is the root of the Java object hierarchy. This point is important because a Java method that is passed an Object reference may have a reference to just about anything.

In contrast to converting and casting primitives, converting and casting a reference to a variable does not change the object being referred to. Once created, an object can be referred to in a variety of ways, but the object type is not changed. However, the reference ...

Get Java 2™ Programmer Exam Cram™ 2 (Exam CX-310-035) now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.