Java polymorphic Example class automatically call the parent class is empty constructor method member variable does not support override writable, no polymorphic effect

Source: Internet
Author: User

======= subclasses are instantiated by default when the parent class is empty, the constructor is super (), which can be omitted.

However, when the parent class does not have an empty construction method, it must call this method in the subclass to instantiate the parent class before the instance class is real.

The default constructor for a parent class that is empty is automatically called by default in the subclass.


======== when a parent class refers to a subclass object, it calls different classes based on the class that the instance belongs to in the reference variable, which applies only to methods that do not apply to member variables . simple to understand that Java does not support attribute field overrides (override), only method overrides are supported, and property fields are not overridable.


when ======== instantiates a subclass, it initializes the constructor of the parent class, but does not produce the object . The parent class has the potential to be an interface, not a default call to an empty constructor method. because the subclass must hold the value of the member variable of the parent class, it is initialized and cannot produce an overridden polymorphic effect for member variables.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Java polymorphic Example class automatically call the parent class is empty constructor method member variable does not support override writable, no polymorphic effect

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.