Concept of Object-Oriented Programming

Source: Internet
Author: User

1. Classes and objects
These two concepts are completely different and cannot be confused.
A Class is a prototype that defines variables and methods for certain types of objects. It represents the abstraction of a class of things with common characteristics in real life, and is the basis of object-oriented programming. A class defines a group of objects. A class is a behavior (be-havoir) that describes what an object can do and the method it uses. They are programs and processes that can operate on this object.
Objects are all things that people need to study. From the simplest integer to the complex aircraft, they can be regarded as objects. They can not only represent specific things, it can also represent abstract rules, plans, or events.
Objects are class instantiation. The meaning of "class instance" is the same as that of "object. For example, if humans are abstract classes, then you and I have every individual person who is an object.
 
2. attributes and fields
A field is a member that represents a variable associated with an object or a class.
A property is a descriptive property or feature of an object. As in the previous example, the height and weight of a person are attributes.
It is common to set fields to private and access them through public attributes.

3. Method
The method is basically known to everyone. I will not talk about it here.
 
Sample Code:
Public class People
{
Public People ()
{
//
// TODO: Add constructor logic here
//
}

Private double height; // Field
Private double weight; // Field
Private int age; // Field

Public double Height // attribute
{
Get {return height ;}
Set {height = value ;}
}

Public double Weight // attribute
{
Get {return weight ;}
Set {weight = value ;}
}

Public int Age // attribute
{
Get {return age ;}
Set {age = value ;}
}

Protected void AddAge () // Method
{
Age ++;
}

}

 

From Kevin

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.