Show TOC

Assignment Rules for Reference VariablesLocate this document in the navigation structure

The content of a reference variable can be assigned only to another reference variable. Here, data references can be assigned only to data reference variables and object references only to object reference variables.

No conversion takes place during these assignments.

 So that such an assignment can take place, the static type of the target reference variable must be more general than or the same as the dynamic type of the source reference variable. This basic rule determines all assignments between reference variables.

For example, a subclass reference can always be assigned to a superclass reference variable, while the assignment of an interface reference variable to a class reference variable must be checked dynamically.

For more information, refer to the keyword documentation.