Java overload/Rewrite (overlay)/refactoring comparisons and their differences with C + + __java

Source: Internet
Author: User

Recently in learning Java, and C + + is a certain difference, the following are more easily confused than the overload, rewrite, refactoring, and its differences with C + +.

About overloading, overriding, and hiding references in C + +: http://blog.csdn.net/zhangjikuan/article/details/38447265

http://blog.csdn.net/zhangjikuan/article/details/38437851

Java:

Overloading: Overloads in Java are the same as C + +

Scope of action: in the same class

Specific: The same method name in the same class, the parameter is different is called overload, for example, a class often have more than one constructor, where the multiple constructors constitute the overload

Note: A constructor is a special case, because the constructor does not return a value, and there is a situation where the other is the same (function name and parameter), but whether the return value is different will not constitute an overload.

No, because the overload is called by different methods depending on the function arguments, but the same return value of the same name and parameter is different so that you don't know which method is invoked at the time of the call, and thus cannot be overloaded.

Rewrite (overwrite): C + + does not have this concept, rewrite is also called overlay, corresponding to the hidden in C + +, covering C + +, but with C + + coverage difference is relatively large.

Scope: base class and derived class

Specific: The name of a function in a derived class is the same as the name of a function in the parent class, but the return value, or cosmetic permission, or parameter is different

Difference: There is more hidden in C + + a case is virtue keyword

Refactoring: Refactoring is the focus of Java, because refactoring forms polymorphism, corresponding to the overlay in C + +

Scope: base classes and derived classes

Specific: The function name parameters in the base class and derived classes return the same value, and only the function body is different, is the basis for the formation of polymorphism

Difference: It is simpler to overwrite than C + +, because overriding the required base class function in C + + is a virtual function, the Java side refactoring does not consider any virtual functions,

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.