📜  下铸java代码示例

📅  最后修改于: 2022-03-11 14:52:38.558000             🧑  作者: Mango

代码示例1
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;
}