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