Question: What changes, taken together, would make the Tree class immutable? (Choose three.) A. Make all constructors private. B. Change the access level of species to

What changes, taken together, would make the Tree class immutable? (Choose three.) 

1: public class Tree { String species; 2: 3: 4: 5: 6:

A. Make all constructors private.

B. Change the access level of species to private.

C. Change the access level of species to protected.

D. Remove the setSpecies() method.

E. Mark the Tree class final.

F. Make a defensive copy of species in the Tree constructor.

1: public class Tree { String species; 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:} public Tree (String species) { this.species species; } public String getSpecies () { return species; } private final void setSpecies (String newSpecies) { species newSpecies; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To create an immutable class in Java we must ensure that its state cannot change after it has been constructed This means that once an object is creat... 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!