CPSC 233 Lecture Notes - Lecture 19: Lookup Table, Late Binding, Downcasting

56 views4 pages

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.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents