Java foundation twelfth day summary - object-oriented (in)

table of Contents:

A rewriting method

Second, the four access rights modifier

Third, keyword: super

Fourth, the subclass object instantiation

Five polymorphisms

/*--------------------------split line----------------*/

A rewriting method

Is defined : in the subclass needs to transform the methods inherited from the parent class based, also known as coating method, and reset.

Requirements :

A method subclasses must override the parent class and a method of rewriting includes the same method name and parameter list

Subclasses override A method return type of the parent class is not greater than the rewritten Return Type

3. The method of using a subclass overrides the access modifier can not be less than the access to the parent to be rewritten

  > Subclass can not override the parent class method declared private rights

4. subclass exception thrown exception is not greater than the parent class is rewritten method

Note :

The method of the same name and the same parameters subclass must declare the parent class's non-static (i.e. rewritable), or both declared static (not rewritable). Because static methods belong to the class, sub-class parent class not covered.

 

Second, the four permission modifier

 

 

 Third, keyword: super

In Java used to call the specified action in the parent class:

Can be used to access attributes defined in the parent class, members of the methods can be used to call the parent class constructor subclass constructor

Note :

When the child the parent class appears members of the same name, you can use super show is called the parent class members

super traceability is not limited to the direct parent

and this super similar usage, this representative of this class object reference to the representative identifier of the memory space of the parent class super

 

Call the parent class constructor:

Subclass default constructor will access the parent class constructor parameter hollow

When the parent is not null constructor parameter, subclass constructor must call statement specifies the parent class or classes present in the corresponding configuration by this (parameter list) or super (parameter list). While only choose one, and must be placed in the first line of the constructor.

If neither the sub-class constructor explicitly call parent class constructor or present, and not the parent class has no argument constructor, the compiler errors.

 

 

 

Fourth, the subclass object instantiation

 

 

 Fifth, the object-oriented features of the three: Polymorphism

Appreciated polymorphism :
a reference point to a child class object Method override the parent class.
Or overwrite subclass object reference assigned to the parent class.

Polymorphism using premise : ② ① class methods inheritance rewrite

Polymorphism object, applies only to the method, does not apply to property (see left compile, run to see the right.)

 

 

Virtual method call :

Person e = new Student();
e.getInfo (); // call getInfo Student class () method
 
instanceof operator
x instanceof A: testing whether the class object x A, the return value boolean type. 

 

 

 

 

Guess you like

Origin www.cnblogs.com/zhoutie170821/p/11829164.html