JAVA Fundamentals 6 - Object Oriented 1

1. Definition of objects

The object is the entity of the existence of the thing, usually the object is divided into two parts: the static part and the dynamic part, the static part is called the property, the dynamic part is called the behavior, and the object is understood by exploring the properties of the object and observing the behavior of the object.

2. Class

1. Definition of class: A class of things with the same characteristics and behaviors is called a class, and a class is a carrier that encapsulates the attributes and behaviors of objects;

2. The main method of the class: the entry point of the class, which defines where the program starts; and provides control over program flow;

格式:public static void main(String[] args){

  method body

}

Features: no return value; static; formal parameters are arrays;

3. Member method: corresponds to the behavior of the class object. Also known as methods, dynamic properties. Can have parameters. When the parameter is an object, an association relationship between classes is established;

Format: permission modifier return value type method name (parameter type parameter name) {

  Method body (if you need a return value, you can use the return keyword)

}

4. Member variable: corresponds to the properties of the class object. Also known as properties, static properties. Member variables can be of any type;

Format: first define the class, and then define the member variables.

permission modifier class class name (first letter capitalized) {

  Permission modifier variable type variable name (the initial value can be set, if not set, there will be a default value)

}

5. Local variables: Variables defined in member methods are created when the method is executed and destroyed when the method is executed, and must be assigned or initialized when used, otherwise a compilation error will occur.

6. Relationship between classes:

  • Association relationship: the definition is not clear, the relationship is weak;
  • Inheritance relationship: what is what, it is logical, the keyword extends;
  • Aggregation relationship: 1. Aggregation: not an essential part; 2. Combination: the combination of a class is essential;
  • Realization relationship: only the result, regardless of the process;

3. Object-oriented features:

1. Encapsulation: It is the core idea of ​​object-oriented programming, which encapsulates the behavior of object attributes; classes usually hide their implementation details from customers, which is the idea of ​​encapsulation; keyword: private/public;

2. Inheritance: The relationship between classes is called an association. Inheritance is a type of association. It mainly uses the common attributes between specific objects. The upper level becomes the parent class, the lower level becomes the subclass, and the instances of the subclass are all the parent class. , but it cannot be said that the instances of the parent class are all instances of the subclass;

3. Polymorphism: applying abstract class objects to subclasses;

4. Object creation (also known as instantiation, made)

In the main method format: class name object name = new object name ()  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325172140&siteId=291194637