Answers for "how do you downcast 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
0

downcasting in java

Downcasting is casting to a subtype, 
going down in the inheritance tree.
It is done to access sub class features.
It has to be done manually

(TakeScreenShot)driver).takeScreenShot();
Posted by: Guest on January-05-2021

Browse Popular Code Answers by Language