0
Complete the code segment to call default constructor first and then any other constructor in the class.
I did this program. Please tell me the correct way to solve this. If the code above the comment should not be changed. https://code.sololearn.com/cuPWiUjDNGr8/?ref=app
1 Answer
0
UseĀ this();Ā in the first line of the parametrized constructor and it will call your default constructor.
class Answer{
Answer(){
System.out.println("You got nothing.");
}
Answer(int marks, String type){
this();
System.out.println("You got "+marks+" for an "+ type);
}
}