Ask Question
24 November, 22:18

Consider the following class declaration.

public class Thing

{

private String color;

public Thing ()

{

color = "Blue";

}

public Thing (String setColor)

{

color = setColor;

}

}

Which of the following code segments, when appearing in a class other than Thing, would create a reference of type Thing with a value of null?

Thing someThing = new Thing ("Green");

A

Thing someThing = new Thing ("");

B

Thing someThing = new Thing ();

C

Thing someThing;

D

Thing ("Green");

E

+1
Answers (1)
  1. 25 November, 00:23
    0
    Thing someThing; is the right answer

    Explanation:

    A. Thing someThing = new Thing ("Green");

    This would create a reference type with value "Green". This is because this calls the constructor with one parameter.

    B. Thing someThing = new Thing ("");

    This would create a reference type with value "" (empty). This is because once again it calls constructor with one parameter.

    C. Thing someThing = new Thing ();

    This would set an object with value as "blue". This is because in no argument constructor, the value of the color is set to blue.

    D. Thing someThing;

    This is the right answer, because it will declare an object but it will not create it. So it has only null value by default.

    E. Thing ("Green"); This is an invalid statement.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Consider the following class declaration. public class Thing { private String color; public Thing () { color = "Blue"; } public Thing ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers