I. basic object-oriented theory 1. object-oriented understanding. For example, an object is actually an individual in reality. Each person is an object. These objects have their own attributes, such as name, age, and gender. The Code is as follows: [java] class Human {int mName; int mAge ;//... void run (); void jump ();//...} class Human {int mName; int mAge ;//... void run (); void jump ();//...} class is the specific description of the object. If a person can run or jump, it is a function in the class. A class is an abstract concept and a description of a specific object. In reality, people are Entity objects of a class. For example, a person named Wang xiao'er: [java] Human Wang xiao'er = new Human (); then he created a Huamn object, Wang xiao'er, wang xiao'er is a Human, and he has all attributes and methods of Human. In object-oriented systems, we don't need to care about the specific implementation of classes, but just need to know their interfaces. Just like driving a car, we don't need to care about the construction of cars and the specific implementation of engines, you only need to know how to use the steering wheel, the accelerator, and the brakes. [java] Wang xiao'er. run (); Wang xiao'er. run (); 2. dependency between classes: One Method in use-a class operates on objects in another class. Aggregation: Objects in has-a class A contain objects in Class B. Inheritance relationship: is-a A inherits class B. In this case, Class A not only has class B methods, but also has its own methods. 3. Object-oriented features (1) Encapsulation: encapsulation is to enclose processes and data, and data access can only be performed through the defined interface. Object-oriented computing begins with the basic concept that the real world can be depicted as a series of completely autonomous and encapsulated objects that access other objects through a protected interface. (2) Inheritance: inheritance is a hierarchical model that connects classes and allows reuse of encouraging classes. It provides a clear way to express commonalities. A new class of an object can be derived from an existing class. This process is called class inheritance. The new class inherits the features of the original class. The new class is called the derived class (subclass) of the original class, and the original class is called the base class (parent class) of the new class ). A derived class can inherit methods and instance variables from its base class, and the class can modify or add new methods to make it more suitable for special needs. Java only supports single inheritance. (3) polymorphism: allows different types of objects to respond to the same message. Functions can have the same name (different parameters, different parameter numbers or different parameter types) boolean isEquals2 (int I); boolean isEquals2 (double I); when calling these two functions, you do not need to distinguish them, the system automatically distinguishes calls based on the parameter type of the function. 4. the interface of an object, such as Wang xiao'er of the above Human object, provides the public function in the Human class. [java] class Human {String mNmae; int mAge; public void setAge (int age) {mAge = age ;}} class Human {String mNmae; int mAge; public void setAge (int age) {mAge = age ;}} this function can be called externally, wang xiao'er. setAge (); you only need to know that you can set the age through setAge (), without the specific implementation of the relationship. This is the encapsulation feature. You only need to provide one interface for external calls. The only concern of external callers is what interfaces are. When implemented in a class, public, private, and protected are used to control external access permissions. 5. for example, there is a Dog class that represents the Dog species. There is a Bird class that represents birds. They are all animals and share common attributes, then they can inherit the Animal class [java] class Animal {String mName; int mSex; void run (); void jump () ;}class Animal {String mName; int mSex; void run (); void jump ();} then the Dog class can inherit from the Animal [java] class Dog extends Animal {} so that the Dog automatically owns the Animal attribute. Every class in java must inherit from another class. If extends is not used, the Object class is implicitly inherited. The Object class is a superclass of all classes. The JDK has the following description: -- class Object-java.lang.Objectpublic class Object is the root class of the class hierarchy. Each class uses an Object as a superclass. All objects (including arrays) implement this class method. JDK1.0