#Help With Constructor Error

1 messages · Page 1 of 1 (latest)

rigid sequoia
#

Implicit super constructor Bird() is undefined. Must explicitly invoke another constructorJava(134217871)

I get this error and i dont know how to fix it lol

paper muskBOT
#

<@&987246399047479336> please have a look, thanks.

paper muskBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

rigid sequoia
#

this is my file

#

this is Bird

#

the parent

thorny orbit
rigid sequoia
thorny orbit
rigid sequoia
#

no im asking if thats what i should do

thorny orbit
#

yes that's right

#

you must call it

#

always

rigid sequoia
#

just Bird()?

#

or super.Bird()

#

or something like that

thorny orbit
#

super(...)

rigid sequoia
#

ah

#

god damn it

proper belfry
#

and it should be the first line as well(not sure if they changed that?)

rigid sequoia
#

i did everything else right on the exam

#

but im getting a 0 because my code didnt compile

thorny orbit
rigid sequoia
#

do i pass the parent variables inside?

#

the constructor

thorny orbit
#

yes

#

you need to understand why you need to do that at the first place

#

let's say you don't call it

rigid sequoia
#

then those variables will be null

thorny orbit
#

then the parent constructor doesn't construct it, so every field is null, and everything that should have been done isn't done, so now you have an object in an invalid state

#

so java ensures that you call it

#

always

#

in fact it ensures that you have at least one constructor too

#

and this even if you don't inherit any class

#

since if you don't inherit class

#

java will make you inherit Object

#

and will add a default constructor

rigid sequoia
#

the thing im confused about is what specifically do i put inside the super(), because my child constructor wasn't passed anything from the parent

thorny orbit
#

which will contain a default super()

rigid sequoia
thorny orbit
#

you need to pass a name and winglength

rigid sequoia
#

my parent constructor takes 2 arguments

thorny orbit
#

yes

#

then pass them

rigid sequoia
#

no but

#

i dont just want to pass two arbitrary arguments

#

like "mike" and 20

thorny orbit
#

then add parameters to Penguin constructor

#

so now you have three parameters

rigid sequoia
#

the problem is that the assignment didnt say that

#

which is why im confused

thorny orbit
#

ah ?

rigid sequoia
#

yeah penguin only took 1 arg

#

and Bird takes 2

thorny orbit
#

can I see the assignment ?

rigid sequoia
#

it was an inclass test

#

so i dont have the paper

#

but im certain

thorny orbit
#

ah

rigid sequoia
#

but you explained it to me now

#

so i know for next time what to do

thorny orbit
#

then talk to your teacher when you will get your copy

rigid sequoia
#

ill let you know if i get an answer

#

thanks a bunch

thorny orbit
#

👍