Given:
public class Message {
String msg;
int noOfWords;
public Message() {
msg += " Thank you";
}
public Message(int noOfWords) {
this.noOfWords = noOfWords;
msg = "Welcome";
Message();
}
public static void main(String args[]) {
Message m = new Message(5);
System.out.println(m.msg);
}
}
What will be the output ?
Answers
Answered by
4
Answer:
Thank you
Welcome
this will be your output
Answered by
3
Answer:
We will get a compilation error.
Message.java:21: error: cannot find symbol
Message();
^
symbol: method Message()
location: class Message
1 error
error: compilation failed
We can call another constructor by using this() and super().
this() is used to call the constructor of the current class. It should be the first line in the constructor.
super() is used to call the constructor of the super class.
Similar questions
History,
1 month ago
Chemistry,
1 month ago
Math,
3 months ago
Science,
10 months ago
Computer Science,
10 months ago