Java after-class job 6

Source: Internet
Author: User

First, the operationTestinherits.java

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

Why do I have to call the constructor of the parent class before the constructor method of the subclass is run? Can you turn around? Why can't it be reversed?

Subclasses are inherited from the parent class, so when you want to create an object with a subclass, you must first establish the object of the parent class, the subclass has the properties and methods of the parent class, it is necessary to allocate memory space to the parent class's properties, and if the data in the parent class needs to be initialized when the object is created, it must be called It cannot be reversed, because the base class and subclass are like real fathers and children, and if the reverse is generational, and there are several subclasses inheriting the parent class for subclasses, it is equivalent to not knowing that the parent class inherits several subclasses if the other is not known.

Third, running Address.java

Four, the operationExplorationjdksource.java

This is actually called in the Main method: 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, the operationFruit.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.

Java after-class job 6

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.