Inheritance and Polymorphism in java, java Polymorphism

Source: Internet
Author: User

Inheritance and Polymorphism in java, java Polymorphism

Inheritance (extends ):

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

2: subclass inherits all contents of the parent class except (private modifier and constructor ).

3: when creating a constructor manually, The subclass must call the constructor of the parent class.

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

5. Subclass instantiation sequence: the parent class is instantiated before the child class is instantiated; the Child class is static before the member class.

 

Polymorphism (refers to a phenomenon ):

1: there must be an inheritance relationship; there must be method rewriting; the parent class references to the subclass object (a condition with polymorphism ).

2: Method Rewriting:

The basic types of return values are the same.

Reference Type parent class> = subclass.

3: Permission modifier of subclass> = parent class.

4: the parent class reference can only call the content that is overwritten inside the subclass.

(Thank you for reading this article. If you have any mistakes, please correct them. Your younger brother will be easy to learn)

 

Related Article

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.