#Return type for the method is missing?

1 messages · Page 1 of 1 (latest)

finite ventureBOT
#

This post has been reserved for your question.

Hey @solid willow! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

spiral pelican
#

void is a return type, public is an access modifier

#

so like. exactly as the error says

#

@solid willow

solid willow
#

fair enough

#

but

spiral pelican
#

Person here is not a method, it's a constructor

#

same for Bil3 in the above method

#

they have the same name as the class and don't have return types

solid willow
#

so i cant create objects in there?

spiral pelican
#

wdym

#

you can, but you can't return anything from constructors

#

you can't call constructors like methods, so you can't really extract a return value
constructors are called automatically via new

#

btw, public Bil3() {} as an empty constructor is unnecessary. if you don't have any constructors, java adds a public empty constructor for you

solid willow
#

jesus christ, but ok i think i understand somewhat, sorry its literally my first week in this Uni course so im still figuring it out

solid willow
spiral pelican
#

if you provide a return type for Bil3 or Person, for example, that turns it into a method that just happens to have the same name as the class, and you would be able to use it like any other method, but you wouldn't be able to use it as a constructor

finite ventureBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.