When Downcasting Is Required?
Uses. Downcasting Is Useful When the Type of the Value Referenced by the Parent Variable Is Known and Often Is Used When Passing a Value as a Parameter. in the...
Uses. Downcasting is useful when the type of the value referenced by the Parent variable is known and often is used when passing a value as a parameter. In the below example, the method objectToString takes an Object parameter which is assumed to be of type String.
What is downcasting and when it is required?
We use it when we need to develop a code that deals with only the parent class. Downcasting is used when we need to develop a code that accesses behaviors of the child class.
What is downcasting mandatory?
2. Which among the following is a mandatory condition for downcasting? Explanation: The downcasting of any object must be done explicitly. This is because the compilers don't support the implicit conversion of a supertype to subtype.