Constructor and member functions

Source: Internet
Author: User

 
Class class resume {private string name; private string sex; private string age; private string timearea; private string company; // constructor. The initialization value is public resume (string name) {This. name = Name ;}/// member function to pass the value public void setpersoninfor (string sex, string age) {This. sex = sex; this. age = age ;}} resume a = New resume (""); // The value passed by the constructor during initialization. setpersoninfor ("male", "29"); // call the value passed by the member function 

What is the difference between the two?

Constructor

Constructor can initialize a class (a member function), but it is different from a member function.

First

No return value. The function name must be the same as the class name,

Second

It is defined as a public function and called by the system when an object is created.

Member Functions

A member function is a kind of action of a class and a form of calling a class. It can use the members of the class, or use the variables defined by the class to use the members through the variables. The reason is that the function is created in the stack memory only when the function is called. At this time, the class has been defined. Of course, you can use the fully defined class type variables.

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.