down casting java

Solutions on MaxInterview for down casting java by the best coders in the world

showing results for - "down casting java"
Edna
15 Jan 2017
1public class Fruit{}  // parent class
2public class Apple extends Fruit{}  // child class
3
4public static void main(String args[]) {
5    // The following is an implicit upcast:
6    Fruit parent = new Apple();
7    // The following is a downcast. Here, it works since the variable `parent` is
8    // holding an instance of Apple:
9    Apple child = (Apple)parent;
10}
similar questions
queries leading to this page
down casting java