Basic concepts in Java Upcasting and Downcasting
Java Upcasting and Downcasting
1.Upcasting :-
The process of assigning an object from the subclass to the variable from the superclass reference can be called upcasting. In upcasting child class will runs always.
The child class object loses its unique properties and methods that are absent from its parent class when upcasting is done. The methods and properties declared in the parent class are the only ones that the resultant object can access.
When you wish to refer to objects of multiple child classes using a single reference type, upcasting comes in handy. As a result, you can build more generic code that works with a variety of object kinds without needing to write unique code for each kind.
2.Downcasting :-
Downcasting is the conversion of the child class assigned to a variable of the parent class back into a child class variable.
Comments
Post a Comment