What is the result?

Given:

01. public class Hello {
02. String title;
03. int value;
04.
05. public Hello() {
06. title += ” World”;
07. }
08.
09. public Hello(int value) {
10. this.value = value;
11. title = “Hello”;
12. Hello();
13. }
14. }

and:

Hello c = new Hello(5);
System.out.println(c.title);

What is the result?

Given:

01. public class Hello {
02. String title;
03. int value;
04.
05. public Hello() {
06. title += ” World”;
07. }
08.
09. public Hello(int value) {
10. this.value = value;
11. title = “Hello”;
12. Hello();
13. }
14. }

and:

Hello c = new Hello(5);
System.out.println(c.title);

What is the result?

A.
Hello

B.
Hello World

C.
Compilation fails.

D.
Hello World 5

E.
The code runs with no output.

F.
An exception is thrown at runtime.

Explanation:
Main.java:12: cannot find symbol
symbol : method Hello()
location: class Hello
Hello();
^
1 error



Leave a Reply 1

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