Java: how does a subclass class neutralize a parent constructor?

How can a subclass constructor class neutralize the parent constructor?

I mean, in the child constructor, we have to use super () – is there a method to create the parent object?

Super example:

class abstract Parent{
  protected String name; 
  public Parent(String name){
    this.name=name;
  }
}

class Child extends Parent{
  public Child(String name,int count){
    super(name);
  }    
}

Solution

Extend the parent object to initialize the child object when it is initialized As a requirement for initialization, parents need a name This can only be given in the initialization of child objects

Then answer your question, No

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>