0
Do not know how to use no-argument constructor and an argument constructor
Hi everyone, I'm working on a project that asked in the code to have one no-argument constructor and one argument constructor, but I don't know how to add it with the code I've already written. Would someone know how to do this? https://code.sololearn.com/cO0cuOnBRqp3/#java
4 Antworten
+ 2
Constructor methods should be written with same name as the containing class and are automatically triggered when we create a new object of that class.
In your case an example would be
Book(){
System.out.println("new Book object");
}
Book(String title){
System.out.println("new book with title"+ title);
}
+ 2
Just like that:
(for book class)
public Book(){
}
public Book(/* argumnets */){
}
+ 1
Aleksei Radchenkov thank you for your help. I was able to figure it out
+ 1
_rk Thank you for answering. I got it!