Home > Java > javaTutorial > body text

Detailed introduction to inheritance and polymorphism in java

零下一度
Release: 2017-06-27 09:48:13
Original
1868 people have browsed it

Inheritance (extends):

 1: object is the parent (base) class of all classes.

 2: The subclass inherits all the contents of the parent class except (private modifications and construction methods).

 3: When a subclass manually creates a constructor, it must call the parent class constructor.

4: In Java, a class can only have one direct parent class (only single inheritance), and can have multiple indirect parent classes.

5: Subclass instantiation order: instantiate the parent class first, then instantiate the subclass; static first, then the members.

Polymorphism (referring to a phenomenon):

1: There must be an inheritance relationship; there must be a method Rewriting; the parent class reference points to the child class object (the condition for polymorphism to occur).

2: Method rewriting:

Return value type The basic types are the same.

Reference type parent class>=subclass.

 3: Permission modifier of subclass >= parent class.

 4: The parent class reference can only call the overwritten (rewritten) content within the subclass.

                                       ett in any mistakes, please correct me, I am a young man with little talent and little knowledge)

The above is the detailed content of Detailed introduction to inheritance and polymorphism in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template