Java Action Brain 5

Source: Internet
Author: User

1. Run the Testinherits.java example, observe the output, and note that the call relationship that summarizes the constructor method between the parent class and the subclass modifies The code of the parent constructor method, explicitly calling Grandparent Another constructor, notice whether the calling code is the first sentence

Conclusion: by Super calling the base class construction method, it must be the first statement in the subclass construction method.

2. After creating an object of immutable class, the properties of this object cannot be changed, and new subclasses cannot be derived from this class.

3. See the Explorationjdksource.java example.

Analysis

In the previous example, the main method actually called: publicvoid println (Object x), which internally called the String class's valueOf method. the object.tostring method is also called inside the valueOf method:

Public String toString () {

Return GetClass (). GetName () + "@" +

Integer.tohexstring (Hashcode ());

}

The Hashcode method is a local method, implemented by the JVM Designer: public native int hashcode ();

4.fruit.java Note the last sentence, a string and an object "add" to get the following results.

Results

In the "+" Operation , when any object is connected to a String object, its toString () is implicitly called. method, by default, this method returns "class name @ + hashcode". To return meaningful information, subclasses can override the toString () method.

Java Action Brain 5

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.