Java show an implicit call to call

When you are not using the default parent class's constructor, call the parent class constructor defined at this time in the constructor of the subclass will be displayed. 

For example:

Parent Class:

class Animal {
Private String name;

// if you define a new constructor
public Animal (String name) {
this.name = name;
}
}

subclasses:

public Dog the extends Animal {

// This is you call the parent class constructor will display, as is a subclass of the default call parent class
// constructor with no arguments Animal ()
public Dog () {
Super ( "dog"); // call the parent class display there constructor parameters

.... // constructor subclass processing
}
}

of course, if you are not in the parent class constructor parameter, a written display, such as:

parent class:

class Animal {
Private String name ;

// no-argument constructor
public Animal () {
..... // treatment
}

// if you define a new constructor
public Animal (String name) {
name = this.name;
}
}

constructor then call the parent class's constructor subclass, it can not be displayed, because the sub-class has a constructor with no arguments, the subclass will automatically call the parent in the constructor class constructor with no arguments already defined.

But in general, a method of using a heavy-duty construction in the parent class, the subclass can be necessary, calling the appropriate constructor parent
When you are not using the default parent class's constructor, call the parent class constructor defined at this time in the constructor of the subclass will be displayed. 

For example:

Parent Class:

class Animal {
Private String name;

// if you define a new constructor
public Animal (String name) {
this.name = name;
}
}

subclasses:

public Dog the extends Animal {

// This is you call the parent class constructor will display, as is a subclass of the default call parent class
// constructor with no arguments Animal ()
public Dog () {
Super ( "dog"); // call the parent class display there constructor parameters

.... // constructor subclass processing
}
}

of course, if you are not in the parent class constructor parameter, a written display, such as:

parent class:

class Animal {
Private String name ;

// no-argument constructor
public Animal () {
..... // treatment
}

// if you define a new constructor
public Animal (String name) {
name = this.name;
}
}

constructor then call the parent class's constructor subclass, it can not be displayed, because the sub-class has a constructor with no arguments, the subclass will automatically call the parent in the constructor class constructor with no arguments already defined.

But in general, a method of using a heavy-duty construction in the parent class, the subclass can be necessary, calling the appropriate constructor parent

Guess you like

Origin www.cnblogs.com/LoveShare/p/11198921.html