Why might one also use a blank constructor?

前端 未结 10 595
傲寒
傲寒 2020-12-16 04:59

I was reading some Java recently and came across something (an idiom?) new to me: in the program, classes with multiple constructors would also always include a blank constr

10条回答
  •  庸人自扰
    2020-12-16 05:25

    You want to create a blank constructor for the classes that extended this class and since it has been extended the class... the child now has super which references the class above it it's parent. In the event the child did not specify super(stuff)... the stuff inside to reference the other constructors to use it will now attempt to reference the empty constructor.

    I'm not sure what the error will be I am coding my first parent object relationship now and was looking up things here ha cheers.

    I guess I should add the moment you make a constructor that isn't the empty one you lose the default empty one so now super() which is default in the extended class won't have something to point to. Of course if you created the extended classes to take care of super by specifying on which gets rid of the default super() then you sidestep this but what if someone wants to use your class and extend from it and didn't realize there isn't an empty set when you could have just created one.

    This is my first post but wanted to take a crack from how I understand it.

提交回复
热议问题