java--Face Object

Source: Internet
Author: User
Tags modifiers visibility

The purpose for which the software appears:
* Use computer language to describe the world
* Solving real-world problems with computers

Object-oriented thinking describes the object-oriented world

The benefits of object-oriented design and development programs:
* Communicate more smoothly
* Improve design and development efficiency

Construction Method:
Construction methods are used to describe the process of object creation, which is called during the creation of an object.

Grammar:
Access modifier constructor Method name () {
Initialize Code
}
Note: The constructor method name must be the same as the class name, no return value;


Method overloads:
* Method name is the same
* Parameter items are different
* Independent of return value and access modifier


This keyword usage:

Call Properties:
this. property name = 100;

Call Method:
This. Method name ();

Call construction Method:
This ();
This (parameter);
How to use: Must be a statement in the constructor method

One of the three main features of object-oriented-encapsulation

The concept of encapsulation:
Encapsulation: Hides some information about a class inside a class, does not allow external programs to access it directly, but instead implements the hidden information through the methods provided by the class
Operation and Access;

Benefits of Encapsulation:
* Hide the implementation details of the class
* Data can only be accessed by a prescribed method
* Easy to join control statements
* Easy to modify the implementation

Steps for encapsulation:
1. Modifying the visibility of attributes
2. Create getter and Setter methods
3. Adding attribute control statements to the Getter\setter method

static modifier:
Static resources belong to a class-level resource, which is shared for all instance objects of a class
The static keyword can be used to modify properties, methods, code blocks, and inner classes
The static modifier's resource, which executes during class loading

1. Properties of static modifiers:
Static keyword-decorated property, which is a shared variable for all instance objects of a class
Access static properties: Class name. property name

2, Static modification method:
The Static keyword-decorated method, which is a statically-named method, can be called directly to the class name. Method Name (). General
is the static method as a tool method
The resource of the object cannot be called in a static method (properties and methods of the object)

3. Static modified code block
Executes when the class is loaded, because the class is loaded only once, so the static code block runs only once,
It is common to use static blocks of code to load some statically-configured resources, such as configuration files;
{
This is the code block, which, like the constructor method, executes when the object is created.
}
static{
This is the static code block.
}

The difference between static and non-static
1. Properties
2. Methods
3. Calling methods
4. Attribution
Static all belongs to class
Non-static belongs to instances and objects

Inherited:
First, the precondition of inheritance:
Between the child class and the parent class, you must satisfy the logical relationship of the subclass is a parent class to inherit

Second, the advantages of inheritance
1. Improve reusability between code (subclass inherits the code of the parent class)
2. Improved maintainability later in the code (you need to add or remove some code in the late code, just modify the parent class code)

Iii. Steps of Succession:
1. Extract the properties and methods from multiple classes to create a parent class
2. After subclasses use the extends keyword to complete inheritance, subclass extends parent class
3. You can call the code of the parent class in the subclass
Note: A single inheritance in Java, only one parent after the extends keyword

Subclass access to parent class Members:

To access the parent class construction method:
Super ();
Super (parameter);

To access the parent class property:
Super. Attribute name;

To access the parent class method:
Super. Method name ();

Note: This and super must both appear in the first line, and they are mutually exclusive

Subclasses cannot inherit from those resources of the parent class:
1.private Members
2. Subclasses are not in the same package as the parent class, members using the default access permissions
3. Construction method


Access modifiers:
1.private Private
2. Default (Friendly) default
3.protected protected
4.public Public

What is the initialization order of multiple inheritance relationships:
1. Parent class Properties
2. Parent class Construction method
3. Sub-class properties
4. Sub-class construction methods


Object Initialization process:
First step: Check that the class is loaded before you create the class (check that the. class file on your hard disk is loaded into memory)
If the file of the parent class is loaded before loading, then the file of this class is loaded
Java uses a policy called lazy loading (load on demand) when loaded, loaded only once.
Second part: Allocate object space, recursively assign all the parent class's property space,
The property is automatically initialized to a value of "0";
Step Three: Attribute assignment
Fourth Step: Call the Parent class's constructor method (default call to the parent class's parameterless constructor method)
Fifth step: Call the construction method of this class


Method overrides:
* Method name is the same
* parameter list is the same
* Return type is the same or its subclass
* Subclass access rights greater than or equal to parent class

The Super keyword accesses the members of the parent class:
Super can only appear in the methods and construction methods of subclasses
Super calls the constructor method, only the first sentence
Super cannot access the private members of the parent class

Abstract Keyword:
Abstract is an abstraction that modifies classes and methods, which we call abstract classes, which we call abstract methods.
1.abstract modifier class, abstract class
Public abstract class name () {}
Abstract classes are used to represent some abstract concepts

Abstract class Features:
* Abstract classes cannot be instantiated
* Abstract classes can have attributes, methods, and construction methods that are used to inherit from subclasses
* Abstract classes are not necessarily abstract methods.

2.abstract retouching method, abstract method
Access modifier abstract return value type method name (parameter list);
Abstract methods do not need to be implemented by subclasses.

Abstract method Features:
* Abstract method without method body
* Abstract methods must appear in abstract classes
* A class that inherits an abstract class must implement all the abstract methods of the parent class

3. Abstract classes can inherit abstract classes

The final keyword, which indicates the ultimate
1.final can be used to modify classes, methods, and properties.
The 2.final decorated class can no longer be inherited. For example: String string is the final decorated class and cannot be inherited

3.final modified method, no more quilt class rewrite

4.final modified variables cannot be changed after initialization
Constant specification Definition: public static final int ace=12;
The reference data type of the final modification, the reference address cannot be changed, but only the first layer is qualified, and the value of the reference type's property can be changed.


Polymorphic:
In life:
The same thing, because of different conditions, produces different results.

In the program:
The same reference type, using different instances to perform different

Two elements to achieve polymorphism:
1. Subclasses overriding parent class methods
2. Use the type of the parent class

Transformation of subclasses to parent class (UP):
Pet pet=new Dog ();

Two forms of polymorphism are implemented:
* Use parent class as method parameter to implement polymorphism
* Use parent class as method return value to implement polymorphism


Parent class to subclass transformation (downward transition)
Forcing type conversions
The premise is: it has been transformed upward
Called: Restore behavior
Grammar:
Subclass name sub-class self-naming = (subclass name) parent class name;
Dog dog = (dog) pet;

Instanceof Operator:
Returns a Boolean type that determines whether an object belongs to a class and an interface
Object instanceof class or interface software is intended to occur:

* Use computer language to describe the world

* Solving real-world problems with computers

Object-oriented thinking describes the object-oriented world

The benefits of object-oriented design and development programs:

* Communicate more smoothly

* Improve shooting and development efficiency

Construction Method:

Construction methods are used to describe the process of object creation, which is called during the creation of an object.

Grammar:

Access modifier constructor Method name () {

Initialize Code

}

Note: The constructor method name must be the same as the class name, no return value;

Method overloads:

* Method name is the same

* Parameter items are different

* Independent of return value and access modifier

This keyword usage:

Call Properties:

this. property name = 100;

Call Method:

This. Method name ();

Call construction Method:

This ();

This (parameter);

How to use: Must be a statement in the constructor method

One of the three main features of object-oriented-encapsulation

The concept of encapsulation:

Encapsulation: Hides some information about a class inside a class, does not allow external programs to access it directly, but instead implements the hidden information through the methods provided by the class

Operation and Access;

Benefits of Encapsulation:

* Hide the implementation details of the class

* Data can only be accessed by a prescribed method

* Easy to join control statements

* Easy to modify the implementation

Steps for encapsulation:

1. Modifying the visibility of attributes

2. Create getter and Setter methods

3. Adding attribute control statements to the Getter\setter method

static modifier:

Static resources belong to a class-level resource, which is shared for all instance objects of a class

The static keyword can be used to modify properties, methods, code blocks, and inner classes

The static modifier's resource, which executes during class loading

1. Properties of static modifiers:

Static keyword-decorated property, which is a shared variable for all instance objects of a class

Access static properties: Class name. property name

2, Static modification method:

The Static keyword-decorated method, which is a statically-named method, can be called directly to the class name. Method Name (). General

is the static method as a tool method

The resource of the object cannot be called in a static method (properties and methods of the object)

3. Static modified code block

Executes when the class is loaded, because the class is loaded only once, so the static code block runs only once,

It is common to use static blocks of code to load some statically-configured resources, such as configuration files;

{

This is the code block, which, like the constructor method, executes when the object is created.

}

static{

This is the static code block.

}

The difference between static and non-static

1. Properties

2. Methods

3. Calling methods

4. Attribution

Static all belongs to class

Non-static belongs to instances and objects

Inherited:

First, the precondition of inheritance:

Between the child class and the parent class, you must satisfy the logical relationship of the subclass is a parent class to inherit

Second, the advantages of inheritance

1. Improve reusability between code (subclass inherits the code of the parent class)

2. Improved maintainability later in the code (you need to add or remove some code in the late code, just modify the parent class code)

Iii. Steps of Succession:

1. Extract the properties and methods from multiple classes to create a parent class

2. After subclasses use the extends keyword to complete inheritance, subclass extends parent class

3. You can call the code of the parent class in the subclass

Note: A single inheritance in Java, only one parent after the extends keyword

Subclass access to parent class Members:

To access the parent class construction method:

Super ();

Super (parameter);

To access the parent class property:

Super. Attribute name;

To access the parent class method:

Super. Method name ();

Note: This and super must both appear in the first line, and they are mutually exclusive

Subclasses cannot inherit from those resources of the parent class:

1.private Members

2. Subclasses are not in the same package as the parent class, members using the default access permissions

3. Construction method

Access modifiers:

1.private Private

2. Default (Friendly) default

3.protected protected

4.public Public

What is the initialization order of multiple inheritance relationships:

1. Parent class Properties

2. Parent class Construction method

3. Sub-class properties

4. Sub-class construction methods

Object Initialization process:

First step: Check that the class is loaded before you create the class (check that the. class file on your hard disk is loaded into memory)

If the file of the parent class is loaded before loading, then the file of this class is loaded

Java uses a policy called lazy loading (load on demand) when loaded, loaded only once.

Second part: Allocate object space, recursively assign all the parent class's property space,

The property is automatically initialized to a value of "0";

Step Three: Attribute assignment

Fourth Step: Call the Parent class's constructor method (default call to the parent class's parameterless constructor method)

Fifth step: Call the construction method of this class

Method overrides:

* Method name is the same

* parameter list is the same

* Return type is the same or its subclass

* Subclass access rights greater than or equal to parent class

The Super keyword accesses the members of the parent class:

Super can only appear in the methods and construction methods of subclasses

Super calls the constructor method, only the first sentence

Super cannot access the private members of the parent class

Abstract Keyword:

Abstract is an abstraction that modifies classes and methods, which we call abstract classes, which we call abstract methods.

1.abstract modifier class, abstract class

Public abstract class name () {}

Abstract classes are used to represent some abstract concepts

Abstract class Features:

* Abstract classes cannot be instantiated

* Abstract classes can have attributes, methods, and construction methods that are used to inherit from subclasses

* Abstract classes are not necessarily abstract methods.

2.abstract retouching method, abstract method

Access modifier abstract return value type method name (parameter list);

Abstract methods do not need to be implemented by subclasses.

Abstract method Features:

* Abstract method without method body

* Abstract methods must appear in abstract classes

* A class that inherits an abstract class must implement all the abstract methods of the parent class

3. Abstract classes can inherit abstract classes

The final keyword, which indicates the ultimate

1.final can be used to modify classes, methods, and properties.

The 2.final decorated class can no longer be inherited. For example: String string is the final decorated class and cannot be inherited

3.final modified method, no more quilt class rewrite

4.final modified variables cannot be changed after initialization

Constant specification Definition: public static final int ace=12;

The reference data type of the final modification, the reference address cannot be changed, but only the first layer is qualified, and the value of the reference type's property can be changed.

Polymorphic:

In life:

The same thing, because of different conditions, produces different results.

In the program:

The same reference type, using different instances to perform different

Two elements to achieve polymorphism:

1. Subclasses overriding parent class methods

2. Use the type of the parent class

Transformation of subclasses to parent class (UP):

Pet pet=new Dog ();

Two forms of polymorphism are implemented:

* Use parent class as method parameter to implement polymorphism

* Use parent class as method return value to implement polymorphism

Parent class to subclass transformation (downward transition)

Forcing type conversions

The premise is: it has been transformed upward

Called: Restore behavior

Grammar:

Subclass name sub-class self-naming = (subclass name) parent class name;

Dog dog = (dog) pet;

Instanceof Operator:

Returns a Boolean type that determines whether an object belongs to a class and an interface

Object instanceof class or interface

The purpose of the software: * To describe the world in computer language * solving real world problems with computers
Object-oriented thinking describes the object-oriented world
The benefits of object-oriented design and development programs: * Communicate more smoothly * improve shooting and development efficiency
Construction method: The construction method is used to describe the process of object creation, and the construction method is called during the creation of the object.
Syntax: Access modifier constructor Method name () {//Initialize code} Note: The constructor method name must be the same as the class name; no return value;
Method Overloading: * Method name same * parameter item different * not related to return value and access modifier

This keyword usage:
Call property: this. property name = 100;
Calling method: this. method name ();
Call constructor Method: This (), this (argument), how to use: Must be a statement in the constructor method


One of the three main object-oriented features-encapsulation encapsulation concept: encapsulation: To hide some of the class information inside the class, not allow the external program to access directly, but through the method provided by the class to achieve the operation and access to the hidden information;
The benefits of Encapsulation: * Hidden class Implementation Details * Only access data through the prescribed method * Easy to join control statements * Easy to modify the implementation
Package steps: 1. Modify the visibility of a property 2. Create Getter and Setter methods 3. Adding attribute control statements to the Getter\setter method


The static modifier: a static resource that belongs to a class-level resource, and for all instance objects of a class, shares the static keyword with resources that can be used to decorate properties, methods, code blocks, and internal class static modifiers, which execute during class loading
1. Static Modified property: Static keyword-decorated property, which belongs to a variable that is shared by all instance objects of the class. Property: Class name. Attribute Name
2, Static modification method: Static keyword-modified method, which is statically method, can be directly called by the class name. Method name (). Typically, static methods are used as tool methods in a static method cannot invoke the object's resources (properties and methods of the object)
3, static modified code block is executed when the class is loaded, because the class is loaded only once, so the static code block is also run only once, usually using static code block to load a few statically resources, such as the configuration file; {This is a block of code, like a constructor, executed at object creation time. } static{here is a static code block}


The difference between static and non-static 1. Property 2. Method 3. Call method 4. Attribution static all belongs to class non-static belongs to instance and object


Inheritance: A precondition for inheritance: between a subclass and a parent class, you must satisfy the logical relationship of the child class is a parent class to inherit
Ii. Advantages of inheritance 1. Improve reusability between code, (the subclass inherits the code of the parent class after inheritance) 2. Improved maintainability of the code later (some code needs to be added or removed later in the code, just modify the parent class code)
Iii. inherited steps: 1. Extract the properties and methods from multiple classes to create a parent class 2. After subclasses use the extends keyword to complete inheritance, subclasses extends Parent Class 3. The code of the parent class can be called in a subclass note: In Java, there can be only one parent class after the extends keyword, which is a single inheritance


Subclass access to parent class Members:
Access the Parent class construction method: Super (); super (parameter);
Access Parent class Properties: Super. Attribute name;
Access the parent class method: Super. Method Name ();
Note: This and super must both appear in the first line, and they are mutually exclusive


Subclasses cannot inherit those resources of the parent class: 1.private members 2. Subclasses are not in the same package as the parent class, and members using the default access Permissions 3. Construction method

Access modifier: 1.private private 2. Default (friendly) default 3.protected protected 4.public public


What is the initialization order of multiple inheritance relationships: 1. Parent Class Property 2. Parent class constructor Method 3. Subclass attribute 4. Subclass Construction Method

Object initialization process: The first step: Before you create a class, Check that the class is loaded (check that the. class file on the hard disk is loaded into memory) if the file of the parent class is loaded first, and then the file of the class is loaded, the policy used by Java is called lazy loading (load on demand) when loaded and loaded only once. The second part: allocating object space, recursively allocating all the parent class's property space, the property is automatically initialized to the "0" value; step three: attribute assignment fourth: Call the parent class's constructor (the default call to the parent class's parameterless constructor method) Fifth step: Call the constructor of this class

Method Overrides: * Method name same * parameter list same * return type same or subclass * Subclass access permission greater than or equal to parent class


The Super keyword accesses the members of the parent class: Super can only appear in the methods of subclasses and construct methods when super calls a constructor method, only the first sentence super cannot access the private members of the parent class


Abstract Keyword: abstract is the meaning of abstraction, you can modify the class and methods, the modified class we call abstract class, the modification method we call the abstract method 1.abstract decorated class, abstract class public the class name () {} Abstract classes are used to represent some abstract concepts
Abstract class Features: * Abstract classes cannot be instantiated * Abstract classes can have attributes, methods, and construction methods, all of which are used to inherit from subclasses * Abstract classes are not necessarily abstract methods.
2.abstract modification method, abstract method access modifier abstractly Returns a value type method name (argument list); Abstract methods do not need to be implemented by subclasses, so the abstract method is characterized by a subclass: * Abstract method without method body * Abstract method must appear in abstract class * A class that inherits an abstract class must implement all the abstract methods of the parent class
3. Abstract classes can inherit abstract classes


Final keyword, which means that the final 1.final can be used to decorate classes, methods, and properties. The 2.final decorated class can no longer be inherited. For example: String string is the final decorated class and cannot be inherited
3.final modified method, no more quilt class rewrite
4.final modified variable initialization can no longer be changed constant specification definition: public static final int ace=12;final decorated reference data type, reference address cannot be changed, but only first level, reference type property value can be changed



Polymorphism: In life: The same thing, due to different conditions, produces different results.
In the program: the same reference type, using different instances to perform different
Two elements to achieve polymorphism: 1. Subclass overrides parent class Method 2. Use the type of the parent class
Subclass-to-parent conversion (upward transformation): Pet pet=new Dog ();
Two forms of polymorphism are implemented: * Using the parent class as a method parameter to implement polymorphism * using the parent class as the method return value to achieve polymorphism

The transformation of a parent class to a subclass (downward transition) enforces a type conversion premise: The transformation is called: Restore behavior Syntax: Subclass name Subclass Self-naming = (subclass name) parent class name; Dog dog = (dog) pet;
Instanceof Operator: Determines whether an object belongs to a class and interface, returns a Boolean object instanceof class or interface

java--Face Object

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.