Let's first understand what is a class?
Class is the encapsulation of logically related functions and data.
Below is my summary of the class:
Knowing a class starts with its members:
The class has
1. Data Member-attribute
2. member functions-methods
Class member functions are mainly used to operate data members in the class.
Let's take a look at the default constructor with parameters:
There are three ways to assign an initial value using the constructor:
1. Use constructor to initialize in class
For example:
Clock (int h = 0, int m = 0, int s = 0)
{
......
}
For example, when a constructor is called without parameters, the default value is used.
Clock C4
2. Pass parameters to the constructor outside the class (pass real parameters ).
For example, when:
Clockmyclock (9, 30, 45)
Myclock. showtime ();
At this time, clock (9,30, 45) is called when an object is created)
3. Use the constructor to initialize the newly created object.
Clock myclock = clock (9, 30, 45)
Clock (9, 30, 45) is a constant of the clock type.
The class introduction is almost the same. What is the relationship between the class and the class? -- Inherit (Child class inherits parent class)
So what is the role of the defined class? Class is the instantiation of objects. Like the relationship between the mold and the casting, let's take a look at the object below:
After an object is created, the same message is received by different types of objects, resulting in different behaviors-polymorphism is the relationship between classes and objects.
Understanding the entire process of object-oriented makes me deeply understand this sentence. Instead of making the same wheel, the process of building a class is to build a model to avoid duplication, let us make full use of our work efficiency! The summary of learning (the process of abstract classes) is the same. The trunk has a leaf, and the rest is the addition of leaves. This process is inheritance. polymorphism depends on our knowledge, then it is used flexibly.