CPSC 233 Lecture Notes - Lecture 19: Lookup Table, Late Binding, Downcasting
Document Summary
Sometimes the association is represented with an object of a derived class(advanced topic to be covered later) Java is strongly typed: checks for type errors at compile time. A class defines a custom data type: a superclass defines supertype, a subclass defines a subtype, (e. g. ) if circle extends shape, shape is the supertype, and circle is the subtype. You can assign a subtype reference to a supertype reference: (e. g. ) Circle my circle = new circle( ); myshape = mycircle; // legal: this is widening conversion. Also called an upcast or safe cast. Remember: a circle is a kind of shape (polymorphism: though not needed, you can use an explicit cast myshape = (shape)mycircle; Ordinarily, you cannot assign a supertype reference to a subtype reference: (e. g. ) Circle mycircle; mycircle = myshape; // won"t compile: can be forced with a cast; mycircle = (circle)myshape, this is a narrowing conversion.