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)