downcasting up casting java code example
Example: down casting java
public class Fruit{} // parent class
public class Apple extends Fruit{} // child class
public static void main(String args[]) {
// The following is an implicit upcast:
Fruit parent = new Apple();
// The following is a downcast. Here, it works since the variable `parent` is
// holding an instance of Apple:
Apple child = (Apple)parent;
}