Java Programming
primer-original-v2mediumJava Programming03 Class And Objects, Date Apiprimer-original-v2

Java Programming Practice Question

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 ?

Answer options

A
Welcome
B
Welcome Thank you
C
Welcome Thank you 5
D
Compilation fails
E
An exception is thrown at runtime f. The code runs with no output

Correct answer: Compilation fails

Explanation

Quick AnswerThe correct answer is Compilation fails because it directly addresses the core logic of Java Programming.

This question has been retained as-is due to its unique context.

Related Java Programming questions

Practice more Java Programming questions

PrimerPrep has independently reviewed practice questions and coding exercises — all free.