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
Math,
22 days ago
English,
22 days ago
India Languages,
22 days ago
Math,
1 month ago
Science,
8 months ago
Computer Science,
8 months ago