#Return type for the method is missing?
1 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @solid willow! Please use
/closeor theClose Postbutton 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.
void is a return type, public is an access modifier
so like. exactly as the error says
@solid willow
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
so i cant create objects in there?
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
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
yeah i was gonna have something in there, at some point
basically constructors are special methods that
- have the same name as the class
- don't have return types
and have access to this()super()
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
💤 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.