【发布时间】:2021-01-24 14:51:25
【问题描述】:
我在玩代码,看代码旁边的评论,我的问题是:
og是子类型还是父类型?
public static void main(String[] args)
{
inherit og = new child();
og.play();
( (child)og).kick((child)og); //kick is a function in child class wi=hich accepts an object of the child class as parameter
// gives an error if we remove explicit conversion
System.out.println(og instanceof child); //true
System.out.println(og instanceof inherit); //true
System.out.println(og.getClass().getSimpleName()); //child
}
【问题讨论】:
标签: java oop inheritance