What is the result of executing XMLMessage.main?

Given classes defined in two different files:

1. package packageA;
2. public class Message {
3. String getText() {
4. return “text”;
5. }
6. }

And:

1. package packageB;
2.
3. public class XMLMessage extends packageA.Message {
4. String getText() {
5. return “<msg>text</msg>”;
6. }
7.
8. public static void main(String[] args) {
9. System.out.println(new XMLMessage().getText());
10. }
11. }

What is the result of executing XMLMessage.main?

Given classes defined in two different files:

1. package packageA;
2. public class Message {
3. String getText() {
4. return “text”;
5. }
6. }

And:

1. package packageB;
2.
3. public class XMLMessage extends packageA.Message {
4. String getText() {
5. return “<msg>text</msg>”;
6. }
7.
8. public static void main(String[] args) {
9. System.out.println(new XMLMessage().getText());
10. }
11. }

What is the result of executing XMLMessage.main?

A.
text

B.
Compilation fails.

C.
<msg>text</msg>

D.
An exception is thrown at runtime.



Leave a Reply 1

Your email address will not be published. Required fields are marked *