java rewrite overloaded

Animal b = Dog()

If no references Animal, some Dog in a way, is an exception, because no such animal methods

To Dog b = Dog ()

Rewrite:

1. Method members subclasses of the parent class rewritable

2. declared as static methods can not be rewritten, final method can not be rewritten, the constructor can not be overridden

3. The child-parent same package: All child-parent process (except private and final) rewritable

4. The child-parent different packages: sub-method in the parent non-final public and private rewritable

Overload:

1. Common constructor overloads

2. The method must be overridden to change the parameter list

The method may be overloaded or subclasses in the same class

4. The method of overload must be changed in the argument list (which may be of the type, the number may be, return type)

Rewrite overloaded difference:

Method name and parameters as: Rewrite

The same method name, different parameters: Overload

 

Guess you like

Origin www.cnblogs.com/acg88688/p/11870572.html
Recommended