Ask Question
17 October, 10:00

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

+5
Answers (1)
  1. 17 October, 13:15
    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?
Find an answer to your question ✅ “Consider the following class declaration. public class Thing { private String color; public Thing () { color = "Blue"; } public Thing ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers