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?

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
The term immutable refers to objects whose state cannot be changed after they are created In the giv... View full answer
Get step-by-step solutions from verified subject matter experts
