Computer Science, asked by dd0166900, 7 hours ago

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 purveshKolhe
4

Answer:

Thank you

Welcome

this will be your output

Answered by dreamrob
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