Answers for "down casting java"

0

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;
}
Posted by: Guest on January-17-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language