One, run Testinherits.java
Calling the base class construction method through super must be the first statement in the subclass construction method.
Two. Why do I have to call the constructor method of the parent class before the constructor of the subclass is run? Can you turn around? Why can't it be reversed?
The main function of the constructor is that the constructor is a special method of the class that is used by the system to automatically invoke the programmer when generating the instance . The constructor method name is the same as the same name and the argument is empty. The child class inherits the parent class by default, inheriting the constructor of the parent class: The subclass has an implicit method: Super (), and if the subclass overrides the constructor then the subclass also implicitly calls Super ().
Three. Running Address.java
Four. Running Explorationjdksource.java
The main method actually calls the public void println (Object x), which internally invokes the ValueOf method of the String class. The Object.ToString method is also called inside the ValueOf method:
Public String toString () {
Return GetClass (). GetName () + "@" + integer.tohexstring (Hashcode ());
}
Five. Running Furit.java
The fruit class overrides the ToString method of the object class. In the "+" operation, when any object is connected to a string object, its ToString () method is called implicitly, and by default, this method returns "class name @ + Hashcode". To return meaningful information, subclasses can override the ToString () method.
Homework after class