The class is abstract;
The object is specific;
A concrete instance of a class is an object;
The object belongs to a class.
Example: "Notebook Computer Class" is a class; "Your laptop" is the specific one in "laptop class", so "your laptop" is an object of "laptop class".
"Notebook Computer Class" describes the characteristics of all laptops; "Your laptop" has its own unique features in addition to the shared features of laptops.
"Notebook Computer class" is an abstract description of the characteristics of the notebook computer, not the only correspondence to a laptop computer.
The objects of classes and classes are 1:n relationships.
Create a class using the class keyword
Class Computer
{
Describe the characteristics of a class
}
Use the members of a class to describe the characteristics of a class, that is, properties and methods.
Classes and objects are inseparable, and in C # The class is instantiated with the keyword new, creating an object
Example:
Computer computer = new computer ();
Create a class:
Example:
Computer |
+cpu + Memory + HDD + Display |
+ Internet () + Play games () + Office () |
(class name)
Properties
Method
attributes can be represented by variables and represented;
The act is expressed by means of a method;
To create a member variable:
Scope: public, which can be accessed directly when an instance of the class is created.
Private, where member variables are accessible only within the class, which is usually the case for methods in the class.
To create a method:
[Scope] Return type method name (parameter)//method parameter in four types, specific reference method in the parameters of an article
{
Method body
}
Example:
Class Computer
{
public i;
public void Get ()
{
return 0;
}
}
Computer computer = new computer ();
You can pass the object name. The variables and methods of the class are called in the way [variable | method name].
Example:
computer.i = 0;
Computer.get ();
Classes and objects