Java Chapter 3 Object Oriented 1

Process-oriented: (abbreviated POP) analyzes the steps needed to solve the problem, and then implements the steps step by step. Focus on resolution steps

​ Open the refrigerator door();

​ Pretend elephant();

​ Close the refrigerator door();

Object-oriented: (abbreviated OOP) to think and solve problems in a classified way. Object-oriented thinking is suitable for dealing with complex problems. Object-oriented thinking conforms to human cognitive habits. Macro, overall design.

Door class

​ Open the door();

​ close();

Refrigerator design class

​ Category

People category

​ Operation();

Process-oriented is suitable for handling simple things, focusing directly on the process, simple and effective.

Object-oriented is suitable for handling complex things.

java class

A class is a description of the properties and behavior of the same class of things.

Define the features of things in the class == car design drawings == .java file

The specific existence of the object == a specific car (actually existing and usable) stored in the memory

​ The member variables of the attribute class of the class are surrounded by the class

​ Member variable definition syntax

​ [Access authority modifier] [modifier] Data type variable name [=value]

​ The member variables of the class behavior class are surrounded by the class

​ [Access permission modifier] [modifier] return value type/void method name ([parameter type parameter name]){

​ [return value];

}

Create car object

​ Take the car class as a template,

Car baoma = new Car(); new keyword + default construction method();

​ Create an object in memory space

Car baoma uses the Car class as a type to declare a variable pointing to a specific object in the memory space

​ Use baoma variables to access properties and methods in the object.

Variable classification

Member variables

​ Member variables are variables defined in the class, outside the method body.
​ Member variables can use any data type in the Java language (including basic types and reference types).
​ When defining a member variable, you can initialize it. If you don't initialize it, Java uses the default value to initialize it.
​ Member variables will be copied from the class to the object when the object is created.
​ Member variables can be accessed by class methods, construction methods and specific class statement blocks.
​ The scope of the member variable is the entire class body.

Local variable

​ Variables defined in methods, construction methods, or statement blocks are called local variables.
​ Local variables can use any data type in the Java language (including basic types and reference types).
​ Local variables must be initialized and assigned before they are used.
​ Variable declaration and initialization are in the method, after the method ends, the variable will be automatically destroyed.

Class variable

​ Class variables: (also called static variables) class variables are also declared in the class, outside the method body, but must be declared as static type.

Method classification

Member methods: member methods are defined in the class. This method is created when the object is created.
Syntax format:
modifier return value type/void method name (parameter list) { method body statement; [return return value] }


Construction method: the method used to create the object

Class method: (also called static method) class method is also declared in the class, but must be declared as static type

Method overload

Method overloading refers to multiple methods with the same name but different parameters can be defined in a class.
When calling, the corresponding method will be selected according to different parameter tables.
Method overloading In the
same class, the
method name is the same, the
parameters are different (there can be three differences), the
number is different, the
type is different, and the
order is different.
Note: Method overloading has nothing to do with the return value type and access authority of the method.

Guess you like

Origin blog.csdn.net/weixin_45636230/article/details/109150459