|
Classes and interfaces all represent types in Java. The object references can be of any of the following three types:
Class-type
When the object reference is pointing to an object of some class, then the reference is of that class-type. For example, in the following code the object reference myAccount is referencing an object of class Account.
Account myAccount = new Account();
The myAccount is a reference of Account class-type.
Interface-type
When the object reference is pointing to an object of a class that implements a particular interface, then it is of that interface type too. For example, in the following code the object reference myAccount is referencing an object of class Account. Assume that the class Account implements an interface called Auditable. Then object reference myAccount is of interface-type Auditable and class-type Account.
Array-type
When an object reference is pointing to an array object, it is of that array-type. For example, in the following code the object reference intArray is referencing an array of integers.
int[] intArray = new int[5];
intArray is a reference of array-type int[]. In addition, it is of interface-type Serializable and Cloneable. The built-in array implements these two interfaces, Serializable and Cloneable. Therefore, all array objects are of interface-type Serializable and Cloneable.