Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

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;
}
 
PREVIOUS NEXT
Tagged: #casting #java
ADD COMMENT
Topic
Name
6+7 =