Question: In java programmig Create a class called CopyByCloning. The class must contain a StringBuffer as an attribute which is initialized to a new StringBuffer() object

In java programmig

Create a class called CopyByCloning. The class must contain a StringBuffer as an attribute which is initialized to a new StringBuffer() object when this class is instantiated. The class will also provide setText() and getText() methods allowing clients of CopyByCloning objects to set and retrieve the StringBuffer data. Also you need to override the clone() method for this class so that instances of it can be cloned as required. Create another file called UseCopyByCloning, which contains a main() method. In this main() instantiate a new CopyByCloning object and initialize the text in it to Hello!. Then create a clone of the object using the .clone() method on it. You will need a second reference to hold on to this cloned copy of the original object. Print out the text in the two objects by calling their .getText() methods. Then call the .setText() method on one of them and change the text to Bye!. Again print out the text from both objects and see what the difference is. Why do the value(s) change as they do?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!