OOP(objective-oriented programming)
the definition of class and objectives
- objective is an item in the real world; such a student, a loan from the bank
- objective could be described as properties and actions, the first word of which could be characterized by data values and the second word of which could be told by functions.
- the properties of an objective could be described as follows:
- abstraction
- polymorphism(多态)
- inheritance
- encapsulation (封装)
- In programming language, objective is just like a kind of data type in generation way. For example, if you want a variable in int data type, we could use the
int a
to generate integer variable named a. There is a question what data type of objective is. The answer is class. - How to generate a class is just like the way to generate the structure:
class Peoples { doube height; double weight; int running(double distance){}}
- now we could construct the objective use
Peoples sunny, hellen, jobs
how to create an objective and access its members
- you need to know a special function named Constructors function:
- feature_1: automatic invocation(自动调用)
- feature_2: has the same name as the defining class(与类本身同名)
- feature_3: no return value(**including void **)
- feature_4: can be overloaded
- feature_5: could have no any argument
- a class may be declared without constructors
- a no argument constructor with an empty body is simplicity declared in the class. (complier will help you to create the no argument constructor function automatically)
- this constructor, called a default constructor is provided automatically only if no constructors are explicitly declared in the class.
- I will use the following example to illustrate the declaration of class and creation of its constructors; of course there is overloading function in creating the class.