Process-oriented
Object-oriented
Object: all objects. One person, one book, one pen ...... Is an object.
Class is the encapsulation body that includes both data and a group of operations acting on data. It is a model abstracted from a certain object that has something in common.
Object → (abstract) → class
Class → (Instance) → object
Classes generally include: variables (member variables), functions (member functions, member methods)
Class features: encapsulation, inheritance, polymorphism, and abstraction.
Encapsulation:
1. Variables of different classes belong to their own objects
2. The member variables of different objects only belong to their own objects.
3. the variables in the object must be operated through their respective functions, which is safer.
Inheritance:
Subclass can inherit the member variables and member methods of the parent class from the parent class.
Polymorphism:
The morphological diversity of a certain type of objects during execution. This phenomenon becomes polymorphism.
1. Declaration class
Class Declaration
{
Member variable Declaration;
Declaration and implementation of member methods;
}
[Modifier (for example: Public)] class <generic> [: parent class] [: interface list]
2. Declare member variables and member Methods
[Modifier] Return Value Type method ([parameter list])
{
Statement sequence;
[Return [return value];
}
3. Member method Overloading
Object Declaration
Class Object
Create an instance
Object = new class Constructor ([parameter list])
Reference object member variables and call object Methods
Object. member variable
Object. Member method ([parameter list])
Constructor: Special member functions. If no constructor is written, the system automatically generates a default constructor.
1. Special writing
No return value. The function name can only be the same as the class name.
2. Execute special
Class is automatically executed during instantiation. Constructor is the earliest member function to be executed. Constructor is a function used to generate objects.
Main function: Initialize an object when it is instantiated and generated.
1. Declare and call the constructor
Public class mydate
{
Public mydate (INT y, int M, int d) // declare the constructor
{// The constructor has the same name as the class. The constructor returns an instance of the class.
Year = y;
Month = m;
Day = D;
}
}
Mydate d = new mydate (2009, 7, 18 );
2. default constructor
Public mydate ()
Overload: functions with the same name and different parameters (number and type) form overload.
The overload is only related to the function name and form parameter, and has nothing to do with the return value.
This
Indicates the object itself.
Access member variables and member methods of this class
This. member variable
This. Member method ([parameter list])
This calls other constructors of the current object. Public bird (string name, string color): This (name)
Is
Object is class;
True is returned if it is true. Otherwise, false is returned.
141010 ● class