gpt4 book ai didi

java - 如何在不使用 super 关键字的情况下使用子类对象调用父类(super class)重写方法?

转载 作者:行者123 更新时间:2023-11-30 07:23:44 24 4
gpt4 key购买 nike

<分区>

我可以在java中用子类对象调用父类覆盖的方法吗?

I tried below example

class First1
{
void show()
{
String msg="You are in first class";
System.out.println(msg);
}
}
class second extends First1
{
void show()
{
String msg="You are in second class";
System.out.println(msg); }
}
}
class CallingMethod extends second
{
void show()
{
String msg="You are in the third class";
System.out.println(msg);
}
public static void main(String[] args)
{
CallingMethod cm=new CallingMethod();
cm.show();
}

}

现在告诉我是否可以打印“我在二等舱”。通过在示例中使用 cm 的 CallingMethod 类的对象,而不在任何地方使用 super 关键字。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com