Java Clone exercises

Source: Internet
Author: User
Tags tostring
(1) Create a mystring class that contains a string object to initialize it with the builder's arguments in the builder. Add a ToString () method and a concatenate () method to append a string object to our inner string. Implement Clone () in MyString. Create two static methods, each of which takes a mystring x handle as its own argument and invokes X.concatenate ("Test"). However, in the second method, first invoke Clone (). Test the two methods and observe their different results.
(2) Create a class named Battery (battery) containing an int that represents the battery number (in the form of a unique identifier). Next, create a class named Toy that contains a battery array and a ToString that prints out all the batteries. Write a Clone () method for toy to automatically close all battery objects. Clone the toy and print out the results to complete the test.
(3) Modify the Checkcloneable.java so that all the Clone () methods can capture the clonenotsupportexception violation, rather than passing it directly to the caller.
(4) Modify Compete.java to add more member objects to the Thing2 and Thing4 classes to see if they can tell whether the timing varies with complexity-a simple linear relationship or a seemingly more complex one.
(5) Create a deep copy of snake from Snake.java.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.