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