Homework after class

Source: Internet
Author: User

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

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.