What is the difference between a method and a function?

Source: Internet
Author: User

A function is a piece of code that is called by name. It can pass in some data (parameters) for processing, then return some data (return value), or no return value.

All the data passed to the function is passed explicitly.

The method is also a piece of code and is called by name, but it is associated with an object. Methods and functions are roughly the same, but there are two main differences:

  1. The data in the method is implicitly passed;
  2. Method can manipulate data inside a class (remember that an object is an instantiation of a class – A class defines a data type, and an object is an instantiation of that data type)

The above is just a brief explanation, ignoring the scope of the problem.

Article Source: http://blog.jobbole.com/44230/

What is the difference between a method and a function?

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.