JAVA- base (Method overloading and rewriting)

1. What is overloaded? What is rewriting? (

Overload (overload): the same method name, parameter list is not the same. (All classes can occur).

Rewriting (override): method name, parameter list, too. (Generally occurs in succession implementations).

2. The method overloading of understanding? (Return type must be the same, otherwise the compiler error)

(For example in the same class) are generally overloaded class with the same name in a plurality of ways, but the number of parameters passed, not the same type is called reload. Suppose you have two methods you the same name, a method parameter is one, the other two methods, you can call to according to your actual situation.

3. overridden method to understand? (Return type must be the same, otherwise the compiler error)

Rewrite process which generally occurs in succession, rewrite can also be called overwritten. Cover, the original parent class method is covered, when an object is called a subclass, it invokes the method overridden, but when there is polymorphic, the parent class method is a method that is not overwritten calls.

4. The method of rewriting precautions?

- must ensure that the same parent-child class method name, parameter list is the same.
- The return value must subclass method [less] parent class method returns the value range.
- Permission subclass method must be greater than or equal] [parent process permission modifier.
ps (public> protected> default> private).

 

Guess you like

Origin www.cnblogs.com/fan123yh/p/10974154.html