Java multi-state after-class homework

Source: Internet
Author: User

First, verify

(1) the subclass and the parent class define the exact same method

• The result is a., Max,201 ,

• The parent class called a method of the subclass, but the variable called in the method is a variable of the subclass

• Self-Summary: A method in a subclass that calls a subclass if a variable of the same name is called.

Summarize:

• When a subclass has the same method as a parent class, and a parent class variable refers to a subclass object, which method is called, determined by the object's own "true" type, that is, the object is a subtype, it calls the method of the subtype, it is the parent type, and it invokes the method of the parent type.

• This feature is actually a concrete representation of the object-oriented "polymorphic" feature.

• If the subclass has the same field as the parent class , The fields in the subclass are substituted or hidden from the fields of the parent class, and the sub-class method accesses the fields in the subclass (not the fields in the parent class). If the subclass method does want to access a field that is hidden in the parent class with the same name, it can be accessed with the super keyword.

• If the subclass is used as a parent class , the field accessed through the subclass is the parent class !

Java multi-state after-class homework

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.