Question: Which statement about the following classes is correct? A. Only Flower is immutable. B. Only Plant is immutable. C. Both classes are immutable. D. Neither

Which statement about the following classes is correct? 

import java.util.*; public class Flower { private final String name; private final

A. Only Flower is immutable.

B. Only Plant is immutable.

C. Both classes are immutable.

D. Neither class is immutable.

E. None of the above as one of the classes does not compile.

import java.util.*; public class Flower { private final String name; private final List counts; public Flower (String name, List counts) { this.name = name; this.counts = new ArrayList (counts); } public final String getName() { return name; } public final List getCounts() { return new ArrayList (counts); }} class Plant { private final String name; private final List counts; public Plant (String name, List counts) { this.name = name; this.counts = new ArrayList (counts); } public String getName() { return name; } public List getCounts() { return new ArrayList (counts); }}

Step by Step Solution

3.42 Rating (161 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The term immutable refers to objects whose state cannot be changed after they are created In the giv... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Oracle Questions!