我有一个名为“parents”的父类和一个名为“child”的子类,它扩展了父类。如果子类和父类都具有相同的参数但行为构造函数不同,那么如果我创建子类对象,它将自动调用我不想要的父类构造函数。这是怎么可能的。
前任。
class parents
{
parents()
{
System.out.println("hello, i am
parents class constructor");
}
}
class child extends parents
{
child()
{
System.out.println("hello, i am
child class constructor");
}
}
class main
{
public static void
main(String[] args)
{
child c = new child();
}
}
现在在这里,
输出是……
hello, i am parents class constructor
hello, i am child class constructor
但我只想...
hello, i am child class constructor
意味着只运行子类构造函数而不是父类。
怎么可能...