1: Object oriented thinking
Object-oriented is a process-oriented programming idea.
Process oriented: Emphasis on the steps of each of these functions
Object-oriented: emphasizes the object and then invokes the function by the object
2: Object-oriented thinking features
A: It's a thought that's more in line with our thinking habits.
B: complex things can be simplified
C: turning us from the executor to the conductor
Development, design, features
Object Oriented development
is to constantly create objects, use objects, and command objects to do things.
Object-oriented design
is to manage and maintain the relationship between objects.
Object-oriented features
Package (encapsulation)
Inheritance (inheritance)
polymorphic (polymorphism)
Overview of Classes and objects:
How do you describe a thing in the real world ?
Example: Student
name , age , gender ...
study , eat , sleep
Properties: Descriptive information about the thing
Behavior: What the thing can do
We learn programming languages in order to simulate things in the real world.
and the programming language we learn The most basic unit in Java is: class.
So, we should put things through the class to reflect:
In this way, we get the correspondence between the real world things and the classes:
things: class:
Properties member Variables
Behavior member Methods
Class: is a set of related properties and behaviors. is an abstract concept.
Object: Is the concrete manifestation of this kind of thing. Specific existence of the individual.
Example:
Student: Class
Monitor: Object
Demo |
Class Student { Defining Variables name String name; Age int age; Address String address; Defining Methods How to learn public void Study () { SYSTEM.OUT.PRINTLN (" Students Love Learning "); } the way to eat public void Eat () { System.out.println (" learn to be hungry, to eat "); } the way to sleep public void sleep () { System.out.println (" Learning tired , to Sleep "); } } |
Write two classes in a java file: A basic class, a test class.
Note: The file name matches the test class name.
How to use it ?
Create objects to use.
How do I create an object ?
format: Class Name Object name = new class name ();
How do I use member variables ?
The name of the object . Variable name
How do I use member methods ?
The name of the object . Method Name (...)
Memory diagram of an object:
Memory graph of two objects:
Memory graphs for three objects:
Java Object-oriented: object-oriented thinking and overview