~/ learn/ comp-308/ cards/ Upcasting & the final keyword
1 of 5

Upcast a subtype into a supertype variable

Upcast a subtype into a supertype variable

Answer

Shape s = new Circle();

Implicit, always-safe upcast. `s`'s static type is `Shape`, so only `Shape` members are callable through it, even though the object is a `Circle`.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/27f5163f-390e-4c37-893d-a9e195435bba/flashcard utf-8 LF