"Java" multi-state after-school action Brain

Source: Internet
Author: User

1.

1. What is the result of the program running on the left?

2. How do you explain that you will get such output?

3. The computer is not wrong, the reason why you get such a running result is also a reason, then from these running results, you can summarize the Java syntax features?

When a subclass has the same method as the 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 child class 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 fields in the subclass are accessed (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!

2. Use polymorphic method to simulate ATM operation flow.

Results:

"Java" multi-state after-school action Brain

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.