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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started