public class Father {
protected String name;
int age;
Father () {
System.out.println ("Father non-parametric constructor");
}
Father (String name) {
SYSTEM.OUT.PRINTLN ("parameter constructor for person");
}
Public, private, protected, subclass can inherit the public, protected
The default is to be private, not inherited,
Java does not support multiple inheritance, C + + support,
Extends: extension, not the meaning of inheritance
void jump (int lenth) {
System.out.println ("lenth =" +lenth);
}
protected void Jump (int num,int a) {
TODO auto-generated Method Stub
SYSTEM.OUT.PRINTLN ("num =" +num+ "a =" +a);
}
static void Fly () {
System.out.println ("I can fly!");
}
}
public class daughter extends Father {
Daughter () {
Super ();
In the constructor of a subclass, you must call the constructor of the parent class,
Super (); The default call to the parent class's parameterless constructor
System.out.println ("daughter parameterless constructor");
}
Daughter (String name) {
Super ("");
System.out.println ("Daughter with parametric constructor: name =" +name);
}
public static void Main (string[] a) {
/* Regardless of which constructor you use, as long as you do not indicate which constructor of the parent class is used (if the parent class is composed of more than one constructor)
The parent class will call your own default constructor when you call your own constructor, and if the parent class is cut with only one parameter constructor, then be careful.
Because when you call your own constructor and the parent class imposes your own constructor, and the constructor that the parent imposes on you does have arguments, it does not add a parameter to it itself.
So it's still in the form of super (), so this is the equivalent of adding "super ()" to your own constructor, which is certainly wrong, because the parent class doesn't have this constructor
So you need to write the right form "super (" ")", so this is a bit strong to buy strong selling meaning. If the parent class consists of a parameterless and an argument constructor, then you do not need to specify, because the constructor that the parent class imposes on you is
*/
New daughter ();
New daughter ("daughter");
No super in Static methods
Super.jump (100);
Super ();
}
}
/*
* Why the parent class imposes its own constructors on subclasses, because subclasses cannot inherit the parent class's
* Constructor function,
* Moreover, constructors generally carry the role of initializing member variables, while subclasses cannot use the constructor of the parent class
* Then you need to write the method again when initializing the member variable.
* */
java-inherited Super's use