How constructor Java class neutron writing

Today made a question, there are about inheritance

I was thinking, how to make the class constructor function to it inherits the parent class's private variable radius assignment, apparently to by calling the constructor in c ++ inside, it can be

Cylinder(double r,double h):Circle(r){

... (code blocks)

}

But in Java I tried it, no, after Baidu, to be called super function, there are many heavy and difficult.

1. First we have to understand that inheritance is not inherited constructor can only be called (implicitly or explicitly)

2. If the parent class does not define or absence constructor argument constructor, constructors for all subclasses default constructor call parent class (i.e. the most front omitted Super ();)

3. If the parent is not no-argument constructor, or the constructor subclass want to call with argument constructor of the parent class (like this question, we want to call with argument constructor to initialize Circle radius), then the first line to explicitly use super ([arg0] [, arg1] ....), explicit call parameter type, the number you want to call, and parameters of the corresponding parent class constructor, attention must be written in the first line, otherwise, the compiler does not pass.

Guess you like

Origin www.cnblogs.com/zlszls3113373723/p/11390958.html