Upcasting and downcasting allows
you to change the reference variable type for an object. The type of the reference
variable determines what methods you can call, but it’s the type of the object
that the variable refers to which determines the methods that will be called.
Unlike downcasting, upcasting is guaranteed by polymorphism.
Similar
to casting numbers, when down casting you need to specify what you’re casting
to in parentheses before the variable. The variable your downcasting to must
refer to the object type that your downcasting to. When your upcasting or
downcasting you can't change the object only the reference variable.
No comments:
Post a Comment