java four properties; java polymorphism; the this () and super ()

java four characteristics : abstraction, encapsulation, inheritance, polymorphism
C ++ three properties : encapsulation, inheritance, polymorphism

java polymorphism:

1. The same behavior has multiple capabilities of different forms or forms.
2. with different interface, Example perform different operations.
3. polymorphism is reflected in a variety of forms of objects.
 
Three necessary conditions occurring polymorphisms

Inheritance 1. 2. 3. override the parent class object reference to point to a child

Polymorphic implementation

1. 3. 2. Interface rewriting abstract and abstract methods

& Super the this:
1.super (): invoke a constructor of a base class (for the first statement should constructor)
2.this (): calling the constructor for this class of another form (which should is the constructor of the first statement
3. call super () must be written in the first line of the subclass constructor or the compiler is not passed. the first statement in the constructor of each subclass are implicitly invoke super (), if not the parent class form of this constructor, then the error will be at compile time.
4.super (), and this () required the constructor in the first line.
5. despite this call can be used a constructor, but you can not call two.
6.this and can not appear in a super constructor inside at the same time, because this is bound to call other constructors, other constructor must also have the presence of super statement, so meaning with a constructor which has the same statement, lost statement, the compiler will not pass.
7.this () and super () both refer to an object, therefore, not be used in a static environment. including: static variables, static methods , Static block.
8. Essentially, this is a pointer to the this object, however, is a super Java keyword.

Published 28 original articles · won praise 24 · views 10000 +

Guess you like

Origin blog.csdn.net/XM_no_homework/article/details/103841107