Java11-Object-oriented
1. What is object-oriented,
2. Three major features of object-oriented (abstract inheritance polymorphism)
3. What is encapsulation
4. What is an object and what is a class
5. Declaration and use of classes
6. How to Build objects
7. Settings for property security
8. Declaration and invocation of construction methods
Review: Three types of reference for Java: Array class interface
1. Programming languages-high-level languages
c:1968 Process-oriented
|
C + +: 1982 Object-oriented
|-java:1994
|-c#/j#: 2000 Enslavement
Oracle:db Ordbms
void Main () {
}
2. What is object-oriented programming?
is to use real-world entities in a programming language to simulate real-world
Entity: An object that exists in the objective world and can be described (attributes) as functional
(In the face of the object is:
The data and the methods of operation of the data are put together as an interdependent whole-object. Abstract the common objects of the same kind, forming a class. Most of the data in a class can only be handled using the methods of this class. The class is connected to the outside world through a simple external interface, and the object communicates with the object through the message. The program flow is determined by the user in use.
Process-oriented is:
Execute from top to bottom, gradually refinement; its program structure is divided into several basic modules according to function, these modules form a tree structure; the relationships between the modules are as simple as possible and functionally independent; Each module consists of three basic structures: sequence, selection, and loop. The specific method of its Modularization implementation is to use subroutines. The program flow is determined when the program is written. )
3. The three main principles of object-oriented:
3.1 Package: Hide what you need security
3.2 Inheritance: Higher code reuse
3.3 polymorphic: Extensible, maintainable
Human
Age:
Name:
Height:
Gender:
Dinner ()
Sleeping ()
Long stay Disciple class
Age: 16
Name: Flower thousand Bones
Height: 1.65f
Gender: Female
Xiu Xian ()
Programmer class
Age: 20
Name: he Tao
Height: 1.7f
Gender: Male
Dozen Peas ()
Programming ()
Real World Information World (mind) machine World
Flower thousand bone =====> data
He Tao
OOP (Object oriented programming):
A. Parsing properties and methods from a set of objects of the same type
B. Encapsulating the same properties and methods into a class
C. Building an object with the appropriate type
3.1 What is a property:
Characteristics of the object
3.2 What is the method:
function of the object (what to do)]
3.3 What is a class?
A class is a type, a generic, an abstract, not a specific
Data type: basic: byte short int long float double char Boolean
Not enough: Build your own type: Composite type
3.4 What is an object?
Specifically, it's specific.
4. The class contains:
4.1 Instance Properties
Requirements: attribute privatization, for security purposes, in order to avoid clients ' direct manipulation of attributes, violate natural rules
Provides a set of getter/setter to encapsulate attributes, providing an interface for user operations
public xxx GetXXX (): Get Data
public void Setxxxx (parameter): Modify data
4.2 Example methods
5. Declarations of classes
public class type name {
Property
Method
}
6. Building Objects
Type Name Object name =new type name ();
6.1 Calling the properties and methods of an object
The name of the object. XXXX ();
7. How to: Construct objects with the same name as the class
The default constructor method
public class name () {
}
property determines the type and number of arguments
public class name (argument type parameter name [,....]) {
}
1.) If a class does not declare any of the constructor methods, the system automatically assigns a default construction method that is used to create the object
Once the user declares the construction method, the system does not make any allocations
2. The construction method can only be placed behind new and cannot be arbitrarily called
3. Call once to build an object
4. Execute before all code
8. Method overloading: Methods with the same method name and different parameters in the same class, representing different methods
System.out.println ("string");
SYSTEM.OUT.PRINTLN (100);
System.out.println (1.23f);
9.public String toString () {
}
10.this: This object
10.1 In the class instead of the later new object, the current run-time object
THIS.name
This.setname ();
10.2 Call your own other constructor methods
This (); You can call your own other construction methods, but you must put them in the first sentence.
11. Access Modifiers
Public: All that is open can be used
Protected: The protection is only for subclasses (different packages can also)
Nothing: Default neighbor only (other classes of the same package)
Private: Only for yourself
My Java Learning note java11-Object-oriented