#Java extra method?
1 messages ยท Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
While you are waiting for getting help, here are some tips to improve your experience:
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.
`public Contacto(String nombre, String telefono) {
this.nombre = nombre;
this.telefono = telefono;
}
**public Contacto() {**
**}**
}`
...
the last part
is 'Contacto' a class ?
by default, if you don't define any constructors, all classes get a no-arg constructor
but if you define at least one, no new constructors are generated
so if you want to bring back the no-arg constructor, you have to define it manually
yes
i didnt understand that part
could you be more clear what needs to be addressed
I uploaded your attachments as gist. That way, they are easier to read for everyone, especially mobile users ๐
I want to know what is the purpose of the last 5 lines of code
I already have the toString defined
you mean the two constructors?
so the "public Contacto(..." makes no sense to me
the last two methods
that
bhut there is another one
or what looks to be another one?
in the code I sent
do you know what they are used for
to give the object the parameters I gave it right?
when is the constructor called?
when you need to "build" the object like with params so if I have public Character(String name, String weapon, String class) for example
right?
it's called when you create an object using new
new Contacto(...)
if you only define a constructor with 2 arguments, then you must pass 2 arguments to your call to new
if you define no constructors, you get a default one with no arguments
but if you define at least one, that one is gone and needs to be enabled manually
therefore, it's added to the code
each constructor defines a way that u can make an object
u got one that has a name and telephonenumber, and one that has no data
ah, so in my case, i can make an object with 2 parameters or with none
yes
now I get it
thx
For the constructor to properly work you need to first define methods for the arguments right?
yes / no. Your answer is a bit dubious due to miss use of terminology. Inside the constructor u can have stuff happening, or u can ( as u say ) use methods to do things, like setters and alike
if the example says that u should put 2 values , then you get the constructor with 2 parametres that you created , otherwise takes the constructor without parametres ( default constructor) .Hope i was clear ๐
@fallow parrot
yu thanks :D
I put in both just to be safe haha
but Im happy I was able to understand why
good ๐