Java: How can a class of a class constructor class neutralize the parent constructor?

How can a class of a class constructor class neutralize the parent constructor?

I mean in the constructor of Child, we have to use super () - is there a way to create a 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);
  }    
}
+3
source share
4 answers

You extend the parent that is initialized when the child is initialized. Well, as a requirement to be initialized, the parent requires a name. This can only be set when the child object is initialized.

So, to answer your question, do not

+1
source

"" "" . (, , , , ).

:

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

class Elephant extends Animal{
public Elephant(String name,int count){
  super(name);
}

}

, , ?

+3

-, ? , , - . Java , .

+1

, super.ParentClassVariable = thingToBeChanged;

class Parent
{
    BufferedReader inKeyboard;
    public Parent()
    {
        inKeyboard = new BufferedReader (new InputStreamReader(System.in));
    }
}

class Child extends Parent
{ 
    public Child()
    {
        super.inKeyboard = new BufferedReader(new FileReader(filename)); 
    }//changes the pointer in the parent object to point to a different reader
}

, , , Parent use... (System.in) , Parent ... ( )

+1

Source: https://habr.com/ru/post/1760207/


All Articles